﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using CE.User;
using CE.CarInsurance;
using CE.Global;
using CE.Database;
using CE.Configuration;
using CE.Company;
using CE.Mail;

public partial class car_Insurance_carAndpolicy_details : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Session[CE.Global.General.UserId] != null && Session[CE.Global.General.UserTypeId] != null)
        //{
        //    if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
        //        Convert.ToInt32(CE.Global.CEUserType.Customer) && Convert.ToInt32(Session[CE.Global.General.UserTypeId]) !=
        //        Convert.ToInt32(CE.Global.CEUserType.Provider))
        //    {
        //        Response.Redirect("LoginAndRegister.aspx");
        //    }
        //}
        //else
        //{
        //    Response.Redirect("LoginAndRegister.aspx");
        //}

        //if (Session[CE.Global.General.UserProfileAndContactComplete] != null)
        //{
        //    if (Session[CE.Global.General.UserProfileAndContactComplete].ToString() == "0")
        //    {
        //        Response.Redirect("Profile.aspx");
        //    }
        //}
        //else
        //{
        //    Response.Redirect("Profile.aspx");
        //}
        if (Request.Params["id"] != null && Request.Params["email"] != null && Request.Params["name"] != null && Request.Params["dob"] != null && Request.Params["gender"] != null)
        {
            Session[General.FB_UserId] = Request.Params["id"].ToString();
            Session[General.UserEmail] = Request.Params["email"].ToString();
            Session[General.UserName] = Request.Params["name"].ToString();
            Session[General.UserDOB] = Request.Params["dob"].ToString();
            Session[General.UserGender] = Request.Params["gender"].ToString();
            Response.Redirect("carandpolicy_details.aspx");
        }
        else if (Session[General.FB_UserId] == null)
        {
            string fb_CanvasUrl = ConfigurationManager.AppSettings["FB_CanvasUrl"].ToString();
            Response.Redirect(fb_CanvasUrl);
        }

        if (Session[CE.Global.General.UserId] == null)
        {
            hplLogin.Visible = true;
        }
        else
        {
            hplLogin.Visible = false;
        }

        if (Session[General.CarPolicyId] != null && Session[General.IsCarRestoreResult] != null)
        {
            Response.Redirect("results.aspx");
        }

        //if (Session[General.UserICNumber] == null)
        //{
        //    Response.Redirect("Profile.aspx");
        //}

        if (Page.ClientScript.IsStartupScriptRegistered("addScriptShowHideAll") == false)
        {
            Page.ClientScript.RegisterStartupScript(Type.GetType("System.String"), "addScriptShowHideDriver", "ShowHideAll();", true);
            //Page.ClientScript.RegisterOnSubmitStatement(Type.GetType("System.String"), "addScriptShowHideSummary", "ShowHideValidationSummaryMessage()");
        }

        if (Session[General.CarId] != null)
        {
            bool _iscomplete = true;
            MyDatabase _db = new MyDatabase();
            string strSql = "SELECT IsComplete FROM [tblUserResult] WHERE ResultType = 'CI' AND ID1 = " + Session[General.CarId].ToString();
            _iscomplete = Convert.ToBoolean(_db.ExecuteScalarSqlStatement(strSql).ToString());
            if (Session[General.AgentId] == null && _iscomplete == true)
            {
                Response.Redirect("~/user/viewresulthistory.aspx");
            }
            else if (Session[General.AgentId] != null && _iscomplete == true)
            {
                Response.Redirect("~/user/logout.aspx");
            }
        }

        if (!Page.IsPostBack)
        {
            //if (Session[General.CarId] != null)
            //{
            //    hplPolicyDetails.Attributes.Add("onclick", "return confirm('Are you sure to go car insurance details step?');");
            //}
            //else
            //{
            //    hplPolicyDetails.NavigateUrl = "";
            //}
            if (Convert.ToInt32(Session[CE.Global.General.UserTypeId]) ==
                Convert.ToInt32(CE.Global.CEUserType.Provider))
            {
                //ibtSaveClose.Visible = false;
            }

            if (Session[CE.Global.General.AgentId] != null)
            {
                //ibtSaveClose.Visible = false;
                lblAgentHeader.Text = "<br/><b>Agent Name : " + Session[General.AgentName].ToString();
                lblAgentHeader.Text += "</b><br/><i>You are login on behalf of customer.<br/>Please sign out after you have done transaction.</i><br/>";
            }

            CE.Provider.InsurerDB _insurerdb = new CE.Provider.InsurerDB();
            DataTable dtPreInsurerComp = _insurerdb.GetPreInsurer(100, 1);
            ddlCurInsuranceCompany.DataSource = dtPreInsurerComp;
            ddlCurInsuranceCompany.DataTextField = dtPreInsurerComp.Columns[0].ColumnName.ToString();
            ddlCurInsuranceCompany.DataValueField = dtPreInsurerComp.Columns[1].ColumnName.ToString();
            ddlCurInsuranceCompany.DataBind();
            ddlCurInsuranceCompany.Items.Insert(0, new ListItem("Select", "-1"));

            //if (Session[General.CarId] != null && Session[General.CarPolicyId] != null)
            //{
            //    //hplCarResults.Attributes.Add("onclick", "return confirm('Are you sure to go results step?');");
            //}
            //else
            //{
            //    hplCarResults.NavigateUrl = "";
            //}

            //hplProfile.Attributes.Add("onclick", "return confirm('Are you sure to go your profile step?');");
            //hplCarDetails.Attributes.Add("onclick", "return confirm('Are you sure to reload this step?');");


            //DataTable dtSeatCapacity = General.GetComboItem("SeatCapacity", "SeatCapacityId", false);
            //ddlSeatCapacity.DataSource = dtSeatCapacity;
            //ddlSeatCapacity.DataTextField = dtSeatCapacity.Columns[0].ColumnName.ToString();
            //ddlSeatCapacity.DataValueField = dtSeatCapacity.Columns[1].ColumnName.ToString();
            //ddlSeatCapacity.DataBind();
            //ddlSeatCapacity.Items.Insert(0, new ListItem("Select", "-1"));
            //dtSeatCapacity = null;

            DataTable dtCarMake = General.GetComboItem("CarMake", " [Description]", true);
            ddlCarMake.DataSource = dtCarMake;
            ddlCarMake.DataTextField = dtCarMake.Columns[0].ColumnName.ToString();
            ddlCarMake.DataValueField = dtCarMake.Columns[1].ColumnName.ToString();
            ddlCarMake.DataBind();
            ddlCarMake.Items.Insert(0, new ListItem("Select", "-1"));
            //ddlCarMake.Items.Insert(1, new ListItem("Others", "9999"));
            dtCarMake = null;

            //GenerateCarMakeModel();
            //CAR POLICY DETAILS 

            string _fromDate = "";
            string _toDate = "";
            DateTime _dtNow = CE.Global.General.GetUTCDateTime();
            _dtNow = _dtNow.AddDays(-1.0d);
            _toDate = _dtNow.Day.ToString() + "/" + _dtNow.Month.ToString() + "/" + _dtNow.Year.ToString();
            _dtNow = _dtNow.AddYears(-1);
            _dtNow = _dtNow.AddDays(1.0d);
            _fromDate = _dtNow.Day.ToString() + "/" + _dtNow.Month.ToString() + "/" + _dtNow.Year.ToString();
            lblLastThreeYear.Text = _fromDate + " To " + _toDate;
            //rfvClaimValue3.ErrorMessage = "Choose Claim Value for " + lblLastThreeYear.Text + " peroid";
            //rfvNoOfClaim3.ErrorMessage = "Choose No. Of Claim for " + lblLastThreeYear.Text + " peroid";

            _dtNow = _dtNow.AddDays(-1.0d);
            _toDate = _dtNow.Day.ToString() + "/" + _dtNow.Month.ToString() + "/" + _dtNow.Year.ToString();
            _dtNow = _dtNow.AddYears(-1);
            _dtNow = _dtNow.AddDays(1.0d);
            _fromDate = _dtNow.Day.ToString() + "/" + _dtNow.Month.ToString() + "/" + _dtNow.Year.ToString();
            lblLastTwoYear.Text = _fromDate + " To " + _toDate;
            //rfvClaimValue2.ErrorMessage = "Choose Claim Value for " + lblLastTwoYear.Text + " peroid";
            //rfvNoOfClaim2.ErrorMessage = "Choose No. Of Claim for " + lblLastTwoYear.Text + " peroid";

            _dtNow = _dtNow.AddDays(-1.0d);
            _toDate = _dtNow.Day.ToString() + "/" + _dtNow.Month.ToString() + "/" + _dtNow.Year.ToString();
            _dtNow = _dtNow.AddYears(-1);
            _dtNow = _dtNow.AddDays(1.0d);
            _fromDate = _dtNow.Day.ToString() + "/" + _dtNow.Month.ToString() + "/" + _dtNow.Year.ToString();
            lblLastYear.Text = _fromDate + " To " + _toDate;

            /*************************Comment on 13/05/2010
            DataTable dtConverageType = General.GetComboItem("CoverageType", false);
            ddlTypeOfConverage.DataSource = dtConverageType;
            ddlTypeOfConverage.DataTextField = dtConverageType.Columns[0].ColumnName.ToString();
            ddlTypeOfConverage.DataValueField = dtConverageType.Columns[1].ColumnName.ToString();
            ddlTypeOfConverage.DataBind();

            ddlTypeOfConverage.Items.Insert(0, new ListItem("Select", "-1"));
            dtConverageType = null; */

            DateTime dtNow = new DateTime();
            dtNow = CE.Global.General.GetUTCDateTime();
            for (int i = 0; i < 61; i++)
            {
                DateTime dtTemp = dtNow.AddDays(i);
                string strDate = dtTemp.Date.Day.ToString("00") + dtTemp.Date.Month.ToString("00") + dtTemp.Date.Year.ToString("0000");
                ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd/MMMM/yyyy"), strDate));
            }
            ddlCoverageComDate.Items.Insert(0, new ListItem("Select", "-1"));
            //usrCoverageComDate.StartYear = CE.Global.General.GetUTCDateTime().Year;
            //usrCoverageComDate.EndYear = CE.Global.General.GetUTCDateTime().Year + 1;
            //usrCoverageComDate.IsNotLessThanToday = true;

            DataTable dtNCD = General.GetComboItem("NCDNextClaim", "[NCDNextId]", true);
            //ddlNCD.DataSource = dtNCD;
            //ddlNCD.DataTextField = dtNCD.Columns[0].ColumnName.ToString();
            //ddlNCD.DataValueField = dtNCD.Columns[1].ColumnName.ToString();
            //ddlNCD.DataBind();
            //ddlNCD.Items.Insert(0, new ListItem("Select", "-2"));
            ddlRenewNCD.Items.Clear();
            for (int i = 0; i < dtNCD.Rows.Count; i++)
            {
                if (Convert.ToInt32(dtNCD.Rows[i][1].ToString()) >= 0)
                {
                    ddlRenewNCD.Items.Add(new ListItem(dtNCD.Rows[i][0].ToString(), dtNCD.Rows[i][1].ToString()));
                }
            }
            ddlRenewNCD.Items.Insert(0, new ListItem("Select", "-1"));
            dtNCD = null;

            /**********************************Comment on 13/05/2010
            DataTable dtClaimValue3 = General.GetComboItem("CarClaimValue", false);
            ddlClaimValue3.DataSource = dtClaimValue3;
            ddlClaimValue3.DataTextField = dtClaimValue3.Columns[0].ColumnName.ToString();
            ddlClaimValue3.DataValueField = dtClaimValue3.Columns[1].ColumnName.ToString();
            ddlClaimValue3.DataBind();
            ddlClaimValue3.Items.Insert(0, new ListItem("Select", "-1"));


            DataTable dtClaimValue2 = dtClaimValue3;
            ddlClaimValue2.DataSource = dtClaimValue2;
            ddlClaimValue2.DataTextField = dtClaimValue2.Columns[0].ColumnName.ToString();
            ddlClaimValue2.DataValueField = dtClaimValue2.Columns[1].ColumnName.ToString();
            ddlClaimValue2.DataBind();
            ddlClaimValue2.Items.Insert(0, new ListItem("Select", "-1"));


            DataTable dtClaimValue1 = dtClaimValue3;
            ddlClaimValue1.DataSource = dtClaimValue1;
            ddlClaimValue1.DataTextField = dtClaimValue1.Columns[0].ColumnName.ToString();
            ddlClaimValue1.DataValueField = dtClaimValue1.Columns[1].ColumnName.ToString();
            ddlClaimValue1.DataBind();
            ddlClaimValue1.Items.Insert(0, new ListItem("Select", "-1"));
            dtClaimValue1 = null;
            dtClaimValue2 = null;
            dtClaimValue3 = null; */

            /*************************Comment on 13/05/2010
            DataTable dtTP = General.GetComboItem("TrafficePoint", false);
            ddlTrafficePoint.DataSource = dtTP;
            ddlTrafficePoint.DataTextField = dtTP.Columns[0].ColumnName.ToString();
            ddlTrafficePoint.DataValueField = dtTP.Columns[1].ColumnName.ToString();
            ddlTrafficePoint.DataBind();
            ddlTrafficePoint.Items.Insert(0, new ListItem("Select", "-1"));
            dtTP = null; */



            if (Session[General.CarPolicyId] != null)
            {
                Int64 _ceuserid = 0;

                if (Session[CE.Global.General.UserId] != null)
                {
                    _ceuserid = Convert.ToInt64(Session[General.UserId]);
                }
                Int64 _cecarid = Convert.ToInt64(Session[General.CarId]);
                Int64 _cepolicyid = Convert.ToInt64(Session[General.CarPolicyId]);
                ShowPolicyDetail(_cecarid, _cepolicyid, _ceuserid);
                //Response.Write("<script type='text/javascript'>alert('1." + UsrCarDriver1.SurName+ "');</script>");
                DriverSetting();
                //Response.Write("<script type='text/javascript'>alert('2." + UsrCarDriver1.SurName + "');</script>");

                OtherValidation();

                //Response.Write("<script type='text/javascript'>alert('3." + UsrCarDriver1.SurName + "');</script>");
                //ibtMyResult.Enabled = true;

            }
            else
            {
                DriverSetting();
                //Page.Validate();
            }
            //============
            int _startYear = CE.Global.General.GetUTCDateTime().Year - 20;
            int _endYear = CE.Global.General.GetUTCDateTime().Year;
            for (int i = _endYear; i >= _startYear; i--)
            {
                ddlManufactYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                ddlRegYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }
            ddlManufactYear.Items.Insert(0, new ListItem("Select", "-1"));
            ddlRegYear.Items.Insert(0, new ListItem("Select", "-1"));

            ddlCarMake.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCarMake.ClientID + "','" + rfvCarMake.ClientID + "');");
            ddlCarModel.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCarModel.ClientID + "','" + rfvCarModel.ClientID + "');");

            ddlManufactYear.Attributes.Add("onblur", "ShowValidationEffect('" + ddlManufactYear.ClientID + "','" + rfvManufactYear.ClientID + "');");
            ddlDiffRegYear.Attributes.Add("onblur", "ShowValidationEffect('" + ddlDiffRegYear.ClientID + "','" + rfvCheckRegYear.ClientID + "');");
            ddlRegYear.Attributes.Add("onblur", "ShowValidationEffectTwo('" + ddlRegYear.ClientID + "','" + rfvRegYear.ClientID + "','" + cpvRegYear.ClientID + "');");

            ddlOffPeak.Attributes.Add("onblur", "ShowValidationEffect('" + ddlOffPeak.ClientID + "','" + rfvOffPeak.ClientID + "');");
            ddlClaimLast3Year.Attributes.Add("onblur", "ShowValidationEffect('" + ddlClaimLast3Year.ClientID + "','" + rfvAnyClaim.ClientID + "');");
            ddlOffFDCom.Attributes.Add("onblur", "ShowValidationEffect('" + ddlOffFDCom.ClientID + "','" + rfvOffenceFDCom.ClientID + "');");
            ddlAddDriver.Attributes.Add("onblur", "ShowValidationEffect('" + ddlAddDriver.ClientID + "','" + rfvAddDriver.ClientID + "');");
            ddlCoverageComDate.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCoverageComDate.ClientID + "','" + rfvCoverComDate.ClientID + "');");
            ddlCurInsuranceCompany.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCurInsuranceCompany.ClientID + "','" + rfvCurInsuranceCompany.ClientID + "');");
            //ddlCarMake.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCarMake.ClientID + "','" + rfvCarMake.ClientID + "');");
            //txtOtherCarMake.Attributes.Add("onblur", "ShowValidationEffect('" + txtOtherCarMake.ClientID + "','" + rfvOtherCarMake.ClientID + "');");
            //txtOtherCarModel.Attributes.Add("onblur", "ShowValidationEffect('" + txtOtherCarModel.ClientID + "','" + rfvOtherCarModel.ClientID + "');");
            //txtOtherCarBody.Attributes.Add("onblur", "ShowValidationEffect('" + txtOtherCarBody.ClientID + "','" + rfvOtherCarBody.ClientID + "');");
            //txtOtherCarCapacity.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtOtherCarCapacity.ClientID + "','" + rfvOtherCarCapacity.ClientID + "','" + csvCCFormat.ClientID + "');");
            //txtSearchCarMakeModel.Attributes.Add("onblur", "ShowValidationEffect('" + txtSearchCarMakeModel.ClientID + "','" + rfvCarMakeModelDesc.ClientID + "');");

            //txtCustomCarMakeModel.Attributes.Add("onblur", "OnBlurCustomCarMakeModel();");
            //ShowValidationEffect('" + txtCustomCarMakeModel.ClientID + "','" + rfvHiddenCustomCarMakeModel.ClientID + "');");

            //ddlCarModel.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCarModel.ClientID + "','" + rfvCarModel.ClientID + "');");
            //ddlSeatCapacity.Attributes.Add("onblur", "ShowValidationEffect('" + ddlSeatCapacity.ClientID + "','" + rfvSeatCapacity.ClientID + "');");
            //rdoYesOffPeak.Attributes.Add("onblur", "CheckOffPeakValidationCss();");

            //rdoNoOffPeak.Attributes.Add("onblur", "CheckOffPeakValidationCss();");
            //rdoYesParallelImport.Attributes.Add("onblur", "CheckParalleImportValidationCss();");

            //rdoNoParallelImport.Attributes.Add("onblur", "CheckParalleImportValidationCss();");

            //txtOffPeak.Attributes.Add("onblur", "ShowValidationEffect('" + txtOffPeak.ClientID + "','" + rfvOffPeak.ClientID + "');");
            //txtParallelImport.Attributes.Add("onblur", "ShowValidationEffect('" + txtParallelImport.ClientID + "','" + rfvParallelImport.ClientID + "');");
            //divOtherCarMake.Visible = false;
            //divOtherCarModel.Visible = false;

            //rfvOtherCarMake.Enabled = false;
            //rfvOtherCarModel.Enabled = false;
            //rfvOtherCarBody.Enabled = false;
            //rfvOtherCarCapacity.Enabled = false;
            //csvCCFormat.Enabled = false;

            //CAR POLICY DETAILS 
            //ddlTypeOfConverage.Attributes.Add("onblur", "ShowValidationEffect('" + ddlTypeOfConverage.ClientID + "','" + rfvCoverageType.ClientID + "');");
            //ddlCoverageComDate.Attributes.Add("onblur", "ShowValidationEffect('" + ddlCoverageComDate.ClientID + "','" + rfvCoverComDate.ClientID + "');");
            //ddlNCD.Attributes.Add("onblur", "ShowValidationEffectMinusTwo('" + ddlNCD.ClientID + "','" + rfvNCD.ClientID + "');");
            ddlRenewNCD.Attributes.Add("onfocus", "JT_ShowTwo('/tooltips/ncdrenew.htm?width=330', '" + ddlRenewNCD.ClientID + "', 'NCD Discount'); return true;");
            ddlRenewNCD.Attributes.Add("onblur", "$('#JT').remove();ShowValidationEffect('" + ddlRenewNCD.ClientID + "','" + rfvRenewNCD.ClientID + "');");
            //ddlTrafficePoint.Attributes.Add("onblur", "ShowValidationEffect('" + ddlTrafficePoint.ClientID + "','" + rfvTrafficPoint.ClientID + "');");
            //ddlSortBy.Attributes.Add("onblur", "ShowValidationEffect('" + ddlSortBy.ClientID + "','" + rfvSortBy.ClientID + "');");
            txtClaimValue3.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtClaimValue3.ClientID + "','" + rfvClaimValue3.ClientID + "','" + revClaimValue3.ClientID + "');");
            txtClaimValue2.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtClaimValue2.ClientID + "','" + rfvClaimValue2.ClientID + "','" + revClaimValue2.ClientID + "');");
            txtClaimValue1.Attributes.Add("onblur", "ShowValidationEffectTwo('" + txtClaimValue1.ClientID + "','" + rfvClaimValue1.ClientID + "','" + revClaimValue1.ClientID + "');");

            //============
            if (Session[General.CarId] != null)
            {
                Int64 _ceid = 0;
                if (Session[CE.Global.General.UserId] != null)
                {
                    _ceid = Convert.ToInt64(Session[General.UserId]);
                }
                Int64 _carid = Convert.ToInt64(Session[CE.Global.General.CarId]);
                ShowCarDetail(_carid, _ceid);
            }
            //if (rdoYesRegYear.Checked || rdoNoRegYear.Checked) txtRegYear.Text = "1";
            //if (rdoNoOffPeak.Checked || rdoYesOffPeak.Checked) txtOffPeak.Text = "1";

            //if (rdoYesParallelImport.Checked || rdoNoParallelImport.Checked) txtParallelImport.Text = "1";
            //lblCarDetailAssumption.Text = MyConfigurationManager.GetAppSettingValue("CarDetailAssumption");

            //CAR POLICY DETAILS 
            //if (rdoYesInsCOEPARF.Checked || rdoNoInsCOEPARF.Checked) txtInsCOEPARF.Text = "1";
            //if (rdoYesDriveMyTh.Checked || rdoNoDriveMyTh.Checked) txtDriveToMyTh.Text = "1";
            //if (rdoYesClaimLast3Year.Checked || rdoNoClaimLast3Year.Checked) txtAnyClaim.Text = "1";
            //if (rdoYesOffFDCom.Checked || rdoNoOffFDCom.Checked) txtOffenceFree.Text = "1";

            //rdoYesClaimLast3Year.Attributes.Add("onmouseover", "JT_ShowTwo('/tooltips/ncdlogic.htm?width=550', '" + rdoYesClaimLast3Year.ClientID + "', 'NCD Discount'); return true;");
            //rdoYesClaimLast3Year.Attributes.Add("onclick", "$('#JT').remove();");
            //rdoYesClaimLast3Year.Attributes.Add("onmouseout", "$('#JT').remove();");
            //if (rdoYesNCDProtection.Checked || rdoNoNCDProtection.Checked) txtNCDProtection.Text = "1";

            //============
            //if (Convert.ToInt32(ddlCarMake.Text) == 9999)
            //{
            //    lblBCCSCDetail.InnerText = "Seating Capacity";
            //}
            //else
            //{
            //    lblBCCSCDetail.InnerText = "Seating Capacity";//, Body and CC";
            //}

            //disable tab
            hplCarResults.NavigateUrl = "";
            hplCarDetails.NavigateUrl = "";


            //Page.Form.DefaultButton = ibtNext.UniqueID;
            Page.Form.DefaultButton = btnNext.UniqueID;

            General.ClearAllSession(this.Page, "CI");
            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();
            //Response.Write("<script type='text/javascript'>alert('5." + UsrCarDriver1.SurName + "');</script>");
        }

    }

    //protected void ibtBack_Click(object sender, ImageClickEventArgs e)
    //{
    //    Response.Redirect("profile.aspx");
    //}

    protected void ibtSaveClose_Click(object sender, ImageClickEventArgs e)
    {
        CheckValidation();
        OtherValidation();
        //rfvSortBy.Enabled = false;
        if (!DriverValidation())
        {
            txtDriverValid.Text = "Not Valid";
        }
        else
        {
            txtDriverValid.Text = "Valid";
        }
        //LoadCarModelList();
        ChangeValidationEffectServerSide("cardetail");
        if (IsValid)
        {
            if (Save())
            {
                //if (ClearUserLoginCached(Session[General.UserId].ToString()))
                //{
                lblMessage.Text = "Saved successfully!";
                General.ClearAllSession(this.Page, "LOGOUT");
                //Response.Redirect("~/User/UserMessage.aspx?ErrorCode=CI501");
                Response.Redirect("~/user/usermessage.aspx?mt=ci&ec=501");
                //ibtNext.Enabled = true;
                //}
            }
            else
            {
                lblMessage.Text = "Saving did NOT succeed!";
            }
        }
        else
        {
            lblMessage.Text = "Please fill all require fields completly and correctly.";
        }
    }

    protected void lnkNext_Click(object sender, EventArgs e)
    {
        if (Session[General.ViewedDetailsId] == null)
        {
            Session[General.ViewedDetailsId] = "0";
        }

        CheckValidation();
        OtherValidation();
        if (!DriverValidation())
        {
            txtDriverValid.Text = "Not Valid";
        }
        else
        {
            txtDriverValid.Text = "Valid";
        }
        if (chkCannotfind.Checked == true)
        {
            //CHANGES
            //txtCarMakeId.Text = "9999";
            //txtCarModelId.Text = "9999";
            txtCustomCarMakeModel.Text = General.ClearScriptTag(txtCustomCarMakeModel.Text);
            txtCustomCarMakeModel.Text = Server.HtmlEncode(txtCustomCarMakeModel.Text);
            //txtCarMakeModelDesc.Text = txtCustomCarMakeModel.Text.Trim();
        }
        //LoadCarModelList();
        ChangeValidationEffectServerSide("cardetail");
        if (CheckClaimValue() == true)
        {
            if (IsValid)
            {
                if (Save())
                {
                    lblMessage.Text = "Saved successfully!";
                    //Response.Redirect("policy_details.aspx");
                    //Response.Redirect("results.aspx?sortby=" + ddlSortBy.Text);                 
                    //Response.Redirect("CarResultRedirect.aspx?sortby=" + ddlSortBy.Text);
                    //ibtNext.Enabled = true;

                    Response.Redirect("profile.aspx");
                }
                else
                {
                    lblMessage.Text = "Saving did NOT succeed!";
                }
            }
            else
            {
                lblMessage.Text = "Please fill all require fields completly and correctly.";
            }
        }
        else
        {
            lblMessage.Text = "Please fill claim value correctly.";
        }
    }


    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (Session[General.ViewedDetailsId] == null)
        {
            Session[General.ViewedDetailsId] = "0";
        }

        CheckValidation();
        OtherValidation();
        if (!DriverValidation())
        {
            txtDriverValid.Text = "Not Valid";
        }
        else
        {
            txtDriverValid.Text = "Valid";
        }
        if (chkCannotfind.Checked == true)
        {
            //CHANGES
            //txtCarMakeId.Text = "9999";
            //txtCarModelId.Text = "9999";
            txtCustomCarMakeModel.Text = General.ClearScriptTag(txtCustomCarMakeModel.Text);
            txtCustomCarMakeModel.Text = Server.HtmlEncode(txtCustomCarMakeModel.Text);
            //txtCarMakeModelDesc.Text = txtCustomCarMakeModel.Text.Trim();
        }
        //LoadCarModelList();
        ChangeValidationEffectServerSide("cardetail");
        if (CheckClaimValue() == true)
        {
            if (IsValid)
            {
                if (Save())
                {
                    lblMessage.Text = "Saved successfully!";
                    //Response.Redirect("policy_details.aspx");
                    //Response.Redirect("results.aspx?sortby=" + ddlSortBy.Text);                 
                    //Response.Redirect("CarResultRedirect.aspx?sortby=" + ddlSortBy.Text);
                    //ibtNext.Enabled = true;

                    //To clear selected result ID
                    if (Session[General.CarResultId] != null)
                    {
                        Session[General.CarResultId] = null;
                        //Session[General.ProviderCompanyId] = null;
                    }

                    Response.Redirect("~/car-insurance/profile.aspx");

                    //Response.Redirect("show-message.aspx");
                }
                else
                {
                    lblMessage.Text = "Saving did NOT succeed!";
                }
            }
            else
            {
                lblMessage.Text = "Please fill all require fields completly and correctly.";
            }
        }
        else
        {
            lblMessage.Text = "Please fill claim value correctly.";
        }
    }

    protected void ibtNext_Click(object sender, ImageClickEventArgs e)
    {

        if (Session[General.ViewedDetailsId] == null)
        {
            Session[General.ViewedDetailsId] = "0";
        }

        CheckValidation();
        OtherValidation();
        if (!DriverValidation())
        {
            txtDriverValid.Text = "Not Valid";
        }
        else
        {
            txtDriverValid.Text = "Valid";
        }
        if (chkCannotfind.Checked == true)
        {
            //CHANGES
            //txtCarMakeId.Text = "9999";
            //txtCarModelId.Text = "9999";
            txtCustomCarMakeModel.Text = General.ClearScriptTag(txtCustomCarMakeModel.Text);
            txtCustomCarMakeModel.Text = Server.HtmlEncode(txtCustomCarMakeModel.Text);
            //txtCarMakeModelDesc.Text = txtCustomCarMakeModel.Text.Trim();
        }
        //LoadCarModelList();
        ChangeValidationEffectServerSide("cardetail");
        if (CheckClaimValue() == true)
        {
            if (IsValid)
            {
                if (Save())
                {
                    lblMessage.Text = "Saved successfully!";
                    //Response.Redirect("policy_details.aspx");
                    //Response.Redirect("results.aspx?sortby=" + ddlSortBy.Text);                 
                    //Response.Redirect("CarResultRedirect.aspx?sortby=" + ddlSortBy.Text);
                    //ibtNext.Enabled = true;

                    //Response.Redirect("profile.aspx");
                    Response.Redirect("show-message.aspx");
                }
                else
                {
                    lblMessage.Text = "Saving did NOT succeed!";
                }
            }
            else
            {
                lblMessage.Text = "Please fill all require fields completly and correctly.";
            }
        }
        else
        {
            lblMessage.Text = "Please fill claim value correctly.";
        }
    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        return _userviewdb.LogViewedHistory("CI", Request, "Car Insurance car detail.");
    }

    private void ShowCarDetail(Int64 CarId, Int64 CEId)
    {
        CarDetail _cardetail = new CarDetail();
        CarDetailDB _cardetaildb = new CarDetailDB();
        _cardetail = _cardetaildb.GetCar(CarId, CEId);
        if (_cardetail != null)
        {
            SetProperty(_cardetail);
        }
        _cardetail = null;
        _cardetaildb = null;
    }

    private void ShowCarDetail(string GUID)
    {
        CarDetail _cardetail = new CarDetail();
        CarDetailDB _cardetaildb = new CarDetailDB();
        _cardetail = _cardetaildb.GetCar(GUID);
        if (_cardetail != null)
        {
            SetProperty(_cardetail);
        }

        _cardetail = null;
        _cardetaildb = null;
    }

    private void SetProperty(CarDetail _cardetail)
    {
        //lblCarId.Text = _cardetail.CECarId.ToString();
        ddlManufactYear.Text = _cardetail.ManufactYear.ToString();
        ddlRegYear.Text = _cardetail.RegYear.ToString();
        if (ddlManufactYear.Text == ddlRegYear.Text)
        {
            //rdoYesRegYear.Checked = false;
            //rdoNoRegYear.Checked = true;
            ddlDiffRegYear.Text = "0";
            divRegYear.Style.Value = "display:none";
        }
        else
        {
            //rdoYesRegYear.Checked = true;
            //rdoNoRegYear.Checked = false;
            ddlDiffRegYear.Text = "1";
            divRegYear.Style.Value = "";
        }

        if (_cardetail.CarMakeId == 9999 && _cardetail.CarModelId == 9999)
        {
            chkCannotfind.Checked = true;
            txtCustomCarMakeModel.Text = _cardetail.MakeModelDesc;
        }
        else
        {
            chkCannotfind.Checked = false;
            ddlCarMake.Text = _cardetail.CarMakeId.ToString();
            ddlCarMake_SelectedIndexChanged(null, null);
            ddlCarModel.Text = _cardetail.CarModelId.ToString();
        }
        CheckCustomCarMakeModel(chkCannotfind.Checked);


        //Sakthi on 24 Jan 2011 --Start
        //txtCarMakeId.Text = _cardetail.CarMakeId.ToString();
        //txtCarModelId.Text = _cardetail.CarModelId.ToString();
        //txtSearchCarMakeModel.Text = _cardetail.MakeModelDesc;
        //txtCarMakeModelDesc.Text = _cardetail.MakeModelDesc;
        //txtCarMakeModelMessage.Text = "";

        //CHANGES
        /*txtCarMakeId.Text = _cardetail.CarMakeId.ToString();
        txtCarModelId.Text = _cardetail.CarModelId.ToString();
        if (txtCarMakeId.Text.Trim() == "9999" && txtCarModelId.Text.Trim() == "9999")
        {
            chkCannotfind.Checked = true;
            txtSearchCarMakeModel.Text = "";
            txtCarMakeModelDesc.Text = _cardetail.MakeModelDesc;
            txtCustomCarMakeModel.Text = _cardetail.MakeModelDesc;
            txtCarMakeModelMessage.Text = "";
        }
        else
        {
            chkCannotfind.Checked = false;
            txtSearchCarMakeModel.Text = _cardetail.MakeModelDesc;
            txtCarMakeModelDesc.Text = _cardetail.MakeModelDesc;
            txtCustomCarMakeModel.Text = "";
            txtCarMakeModelMessage.Text = "";
        }*/
        //Sakthi on 24 Jan 2011 --End

        //rdoYesOffPeak.Checked = _cardetail.IsPeak;
        //if (!rdoYesOffPeak.Checked) rdoNoOffPeak.Checked = true;
        ddlOffPeak.Text = _cardetail.IsPeak ? "1" : "0";
        ddlCurInsuranceCompany.Text = _cardetail.Info1;
    }

    protected void CheckCCValueValidate(object source, ServerValidateEventArgs args)
    {
        try
        {
            // Test whether the lenght of value is < 8 or Is Number Value.

            if (args.Value.Length < 3)
            {
                args.IsValid = false;
            }
            else
            {
                int i = int.Parse(args.Value);
                if (i > 0)
                {
                    args.IsValid = true;
                }
                else
                {
                    args.IsValid = false;
                }
            }
        }
        catch (Exception ex)
        {
            args.IsValid = false;
        }
    }

    private void CheckValidation()
    {
        //if (rdoNoOffPeak.Checked == false && rdoYesOffPeak.Checked == false)
        //{
        //    rfvOffPeak.IsValid = false;
        //}
        //else
        //{
        //    txtOffPeak.Text = "1";
        //    rfvOffPeak.Validate();
        //}

        //if (rdoNoRegYear.Checked == false && rdoYesRegYear.Checked == false)
        //{
        //    rfvCheckRegYear.IsValid = false;
        //}
        //else
        //{
        //    txtRegYear.Text = "1";
        //    rfvCheckRegYear.Validate();
        //}

        //if (rdoYesRegYear.Checked)
        //{
        //    rfvRegYear.Enabled = true;
        //    cpvRegYear.Enabled = true;
        //}
        //else
        //{
        //    rfvRegYear.Enabled = false;
        //    cpvRegYear.Enabled = false;
        //}

        //CHANGES 
        if (chkCannotfind.Checked == true)
        {
            //rfvCarMakeModelDesc.Enabled = false;
            rfvCustomCarMakeModel.Enabled = true;
        }
        else
        {
            //rfvCarMakeModelDesc.Enabled = true;
            rfvCustomCarMakeModel.Enabled = false;
        }
        Page.Validate();
    }

    private bool Save()
    {
        Int64 _carresult = 0;
        Int64 _policyresult = 0;

        CarDetail _car = new CarDetail();
        CarDetailDB _cardb = new CarDetailDB();

        ProfileDB _profiledb = new ProfileDB();
        Profile _profile = new Profile();


        Int64 _refceuserid = 0;

        if (Session[CE.Global.General.UserId] != null)
        {
            _refceuserid = Convert.ToInt64(Session[General.UserId]);
        }


        if (Session[General.CarId] != null)
        {
            _car.CECarId = Convert.ToInt64(Session[General.CarId].ToString());
            if (Session[General.AgentId] != null)
            {
                _car.Info5 = "UPDATE";
            }
        }
        else
        {
            if (Session[General.AgentId] != null)
            {
                _car.Info4 = "NEW";
            }
        }

        _car.ManufactYear = Convert.ToInt32(ddlManufactYear.Text);
        if (ddlDiffRegYear.Text == "1")
        {
            _car.RegYear = Convert.ToInt32(ddlRegYear.Text);
        }
        else
        {
            _car.RegYear = Convert.ToInt32(ddlManufactYear.Text);
        }

        if (Session[General.AgentId] != null)
        {
            _car.Info2 = Session[General.AgentId].ToString();
            _car.Info3 = CE.Global.General.GetUTCDateTime().ToString();
        }

        if (chkCannotfind.Checked)
        {
            _car.CarMakeId = 9999;
            _car.CarModelId = 9999;
            _car.MakeModelDesc = txtCustomCarMakeModel.Text;
        }
        else
        {
            _car.CarMakeId = Convert.ToInt32(ddlCarMake.Text); //Convert.ToInt32(txtCarMakeId.Text);
            _car.CarModelId = Convert.ToInt32(ddlCarModel.Text);//Convert.ToInt32(txtCarModelId.Text);
            _car.MakeModelDesc = ddlCarMake.SelectedItem.Text + " " + ddlCarModel.SelectedItem.Text; //txtCarMakeModelDesc.Text;
        }

        //_car.IsPeak = rdoYesOffPeak.Checked;
        if (ddlOffPeak.Text == "1")
        {
            _car.IsPeak = true;
        }
        else
        {
            _car.IsPeak = false;
        }
        _car.IsParalleImport = false;// rdoYesParallelImport.Checked;
        _car.Status = "CARREQUEST";
        _car.RefCEUserId = _refceuserid;
        _car.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
        _car.CurrentStep = 1;
        _car.TotalStep = 4;

        _profile = _profiledb.GetProfile(_refceuserid);
        if (_profile != null)
        {
            //Save User Profile
            _car.Info10 = _profile.SurName.ToString();
            _car.Info11 = _profile.Gender.ToString();
            _car.Info12 = _profile.DOB.ToString("dd-MMM-yyyy");
            _car.Info13 = _profile.Occupation.ToString();
            _car.Info14 = _profile.JobNature.ToString();
            _car.Info15 = _profile.MaritalStatus.ToString();
            _car.Info16 = _profile.YearDriveSg.ToString();
        }

        _car.Info1 = ddlCurInsuranceCompany.Text;

        _carresult = _cardb.Insert(_car);

        _car = null;
        _cardb = null;
        _profile = null;
        _profiledb = null;

        if (_carresult > 0)
        {
            Session[CE.Global.General.CarId] = _carresult.ToString();
        }
        else
        {
            lblMessage.Text = "Insert error!";
        }
        //return _result > 0;
        if (_carresult > 0)
        {
            //CAR POLICY DETAILS
            CarPolicy _carpolicy = new CarPolicy();
            CarPolicyDB _carpolicydb = new CarPolicyDB();
            Int64 _carId = Convert.ToInt64(Session[General.CarId].ToString());


            Int64 _ceuserid = 0;

            if (Session[General.UserId] != null)
            {
                _ceuserid = Convert.ToInt64(Session[General.UserId].ToString());
            }

            Int64 _carpolicyid = 0;

            if (Session[General.CarPolicyId] != null)
            {
                _carpolicyid = Convert.ToInt64(Session[General.CarPolicyId].ToString());
                _carpolicy.CECarPolicyId = _carpolicyid;
                if (Session[General.AgentId] != null)
                {
                    _carpolicy.Info5 = "UPDATE";
                }
            }
            else
            {
                if (Session[General.AgentId] != null)
                {
                    _carpolicy.Info4 = "NEW";
                }
            }

            lblMessage.Text = "";
            if (Session[General.AgentId] != null)
            {
                _carpolicy.Info2 = Session[General.AgentId].ToString();
                _carpolicy.Info3 = CE.Global.General.GetUTCDateTime().ToString();
            }
            _carpolicy.CECarId = _carId;
            _carpolicy.TypeOfCoverage = "0";
            //string strDate = ddlCoverageComDate.Text.Substring(3, 2) + "/" + ddlCoverageComDate.Text.Substring(0, 2) + "/" + ddlCoverageComDate.Text.Substring(6, 4);

            string strDate = ddlCoverageComDate.Text;
            int _iDay = Convert.ToInt32(strDate.Substring(0, 2));
            int _iMonth = Convert.ToInt32(strDate.Substring(2, 2));
            int _iYear = Convert.ToInt32(strDate.Substring(4, 4));
            _carpolicy.CoverageCommenceDate = new DateTime(_iYear, _iMonth, _iDay);


            //_carpolicy.NCDPercent = Convert.ToSingle(ddlNCD.SelectedValue);
            _carpolicy.NCDPercent = GetExistingNCD();

            if (ddlRenewNCD.Text == "60")
                _carpolicy.Info1 = "50";
            else
                _carpolicy.Info1 = ddlRenewNCD.Text;

            //_carpolicy.Info2 = ddlNCDYear.Text;
            //_carpolicy.IsClaimLastThreeYear = rdoYesClaimLast3Year.Checked;
            if (ddlClaimLast3Year.Text == "1")
            {
                _carpolicy.IsClaimLastThreeYear = true;
            }
            else
            {
                _carpolicy.IsClaimLastThreeYear = false;
            }
            _carpolicy.IsInsCOE = false; // rdoYesInsCOEPARF.Checked;
            _carpolicy.IsDriveMyOrTh = false; //  rdoYesDriveMyTh.Checked;

            //carpolicy.IsOffDriveCom = rdoYesOffFDCom.Checked;
            if (ddlOffFDCom.Text == "1")
            {
                _carpolicy.IsOffDriveCom = true;
            }
            else
            {
                _carpolicy.IsOffDriveCom = false;
            }

            _carpolicy.TPDP = "0"; // ddlTrafficePoint.Text;
            _carpolicy.IsNCDProtection = false; // rdoYesNCDProtection.Checked;
            //_carpolicy.IsAddDriver = rdoYesAddDriver.Checked;
            if (ddlAddDriver.Text == "1")
            {
                _carpolicy.IsAddDriver = true;
            }
            else
            {
                _carpolicy.IsAddDriver = false;
            }
            _carpolicy.NoOfDriver = Convert.ToInt16(ddlDriverCount.SelectedValue);
            _carpolicy.RefCEUserId = _ceuserid;
            _carpolicy.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
            _carpolicy.Status = "SAVENEW";
            _carpolicy.CurrentStep = 2;
            _policyresult = _carpolicydb.Insert(_carpolicy);
            if (_policyresult > 0)
            {
                Session[General.CarPolicyId] = _policyresult.ToString();
                if (_carpolicy.IsClaimLastThreeYear)
                {
                    CarClaimHistory _claimhis = new CarClaimHistory();
                    CarClaimHistoryDB _claimhisdb = new CarClaimHistoryDB();

                    if (Session[General.CarClaimHistoryId] != null)
                    {
                        _claimhis = _claimhisdb.GetCarClaimHistory(Convert.ToInt64(Session[General.CarClaimHistoryId]));
                    }

                    _claimhis.CECarId = _carId;
                    _claimhis.RerCEUserId = _ceuserid;

                    if (Convert.ToInt32(ddlNoOfClaim3.SelectedValue) > 0)
                    {
                        _claimhis.NoOfClaimInLast3Year = Convert.ToByte(ddlNoOfClaim3.SelectedValue);
                        _claimhis.Last3YearClaimValue = txtClaimValue3.Text;
                    }
                    else
                    {
                        _claimhis.NoOfClaimInLast3Year = 0;
                        _claimhis.Last3YearClaimValue = "0";
                    }

                    if (Convert.ToInt32(ddlNoOfClaim2.SelectedValue) > 0)
                    {
                        _claimhis.NoOfClaimInLast2Year = Convert.ToByte(ddlNoOfClaim2.SelectedValue);
                        _claimhis.Last2YearClaimValue = txtClaimValue2.Text;
                    }
                    else
                    {
                        _claimhis.NoOfClaimInLast2Year = 0;
                        _claimhis.Last2YearClaimValue = "0";
                    }

                    if (Convert.ToInt32(ddlNoOfClaim1.SelectedValue) > 0)
                    {
                        _claimhis.NoOfClaimInLast1Year = Convert.ToByte(ddlNoOfClaim1.SelectedValue);
                        _claimhis.Last1YearClaimValue = txtClaimValue1.Text;
                    }
                    else
                    {
                        _claimhis.NoOfClaimInLast1Year = 0;
                        _claimhis.Last1YearClaimValue = "0";
                    }
                    _claimhis.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                    _claimhis.Status = "Active";
                    Int64 _resultclaimhis = _claimhisdb.Insert(_claimhis);
                    if (_resultclaimhis > 0)
                    {
                        Session[General.CarClaimHistoryId] = _resultclaimhis.ToString();
                        lblMessage.Text += "Car claim history saved successfully!";
                    }
                    else
                    {
                        lblMessage.Text += "Car claim history did not save successfully!";
                    }
                    _claimhis = null;
                    _claimhisdb = null;
                }
                else
                {
                    if (Session[General.CarClaimHistoryId] != null)
                    {
                        CarClaimHistoryDB _carclaimdb = new CarClaimHistoryDB();
                        if (_carclaimdb.UpdateStatus(Convert.ToInt64(Session[General.CarClaimHistoryId])))
                        {

                        }
                    }
                }

                lblMessage.Text += "<br>Car policy saved successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                lblMessage.Text = "Car policy did not save successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                return false;
            }

            CarDriver _cardriver = new CarDriver();
            CarDriverDB _cardriverdb = new CarDriverDB();

            if (ddlAddDriver.Text == "1")
            {

                int _drivercount = Convert.ToInt32(ddlDriverCount.SelectedValue);
                int _insertcount = 0;
                _cardriverdb.UpdateAllStatus(_carId, _ceuserid);

                for (int i = 1; i <= _drivercount; i++)
                {
                    _cardriver.StepId = 1;
                    _cardriver.RerCEUserId = _ceuserid;
                    _cardriver.CECarId = _carId;
                    if (i == 1)
                    {
                        UsrCarDriver1.SetProperty();
                        UsrCarDriver1.IsEnabled = true;
                        _cardriver.CarDriverId = UsrCarDriver1.DriverId;
                        //_cardriver.Salutation = UsrCarDriver1.Salutation;
                        //_cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver1.SurName));
                        //_cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver1.GivenName));
                        _cardriver.DOB = UsrCarDriver1.DOB;
                        _cardriver.Gender = UsrCarDriver1.Gender;
                        _cardriver.MaritalStatus = UsrCarDriver1.MaritalStatus;
                        _cardriver.Occupation = UsrCarDriver1.Occupation;
                        _cardriver.JobNature = UsrCarDriver1.JobNature;
                        //_cardriver.IDType = UsrCarDriver1.IDType;
                        //_cardriver.IDNo = UsrCarDriver1.IDNo;
                        _cardriver.YearOfDrivingInSg = UsrCarDriver1.YearsOfDriving;
                        _cardriver.Status = "Active";
                    }
                    else if (i == 2)
                    {
                        UsrCarDriver2.SetProperty();
                        UsrCarDriver2.IsEnabled = true;
                        _cardriver.CarDriverId = UsrCarDriver2.DriverId;
                        //_cardriver.Salutation = UsrCarDriver2.Salutation;
                        // _cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver2.SurName));
                        //_cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver2.GivenName));
                        _cardriver.DOB = UsrCarDriver2.DOB;
                        _cardriver.Gender = UsrCarDriver2.Gender;
                        _cardriver.MaritalStatus = UsrCarDriver2.MaritalStatus;
                        _cardriver.Occupation = UsrCarDriver2.Occupation;
                        _cardriver.JobNature = UsrCarDriver2.JobNature;
                        //_cardriver.IDType = UsrCarDriver2.IDType;
                        //_cardriver.IDNo = UsrCarDriver2.IDNo;
                        _cardriver.YearOfDrivingInSg = UsrCarDriver2.YearsOfDriving;
                        _cardriver.Status = "Active";
                    }
                    else if (i == 3)
                    {
                        UsrCarDriver3.SetProperty();
                        UsrCarDriver3.IsEnabled = true;
                        _cardriver.CarDriverId = UsrCarDriver3.DriverId;
                        //_cardriver.Salutation = UsrCarDriver3.Salutation;
                        //_cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver3.SurName));
                        //_cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver3.GivenName));
                        _cardriver.DOB = UsrCarDriver3.DOB;
                        _cardriver.Gender = UsrCarDriver3.Gender;
                        _cardriver.MaritalStatus = UsrCarDriver3.MaritalStatus;
                        _cardriver.Occupation = UsrCarDriver3.Occupation;
                        _cardriver.JobNature = UsrCarDriver3.JobNature;
                        //_cardriver.IDType = UsrCarDriver3.IDType;
                        //_cardriver.IDNo = UsrCarDriver3.IDNo;
                        _cardriver.YearOfDrivingInSg = UsrCarDriver3.YearsOfDriving;
                        _cardriver.Status = "Active";
                    }
                    else if (i == 4)
                    {
                        UsrCarDriver4.SetProperty();
                        UsrCarDriver4.IsEnabled = true;
                        _cardriver.CarDriverId = UsrCarDriver4.DriverId;
                        //_cardriver.Salutation = UsrCarDriver4.Salutation;
                        //_cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver4.SurName));
                        //_cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver4.GivenName));
                        _cardriver.DOB = UsrCarDriver4.DOB;
                        _cardriver.Gender = UsrCarDriver4.Gender;
                        _cardriver.MaritalStatus = UsrCarDriver4.MaritalStatus;
                        _cardriver.Occupation = UsrCarDriver4.Occupation;
                        _cardriver.JobNature = UsrCarDriver4.JobNature;
                        //_cardriver.IDType = UsrCarDriver4.IDType;
                        //_cardriver.IDNo = UsrCarDriver4.IDNo;
                        _cardriver.YearOfDrivingInSg = UsrCarDriver4.YearsOfDriving;
                        _cardriver.Status = "Active";
                    }
                    else if (i == 5)
                    {
                        UsrCarDriver5.SetProperty();
                        UsrCarDriver5.IsEnabled = true;
                        _cardriver.CarDriverId = UsrCarDriver5.DriverId;
                        //_cardriver.Salutation = UsrCarDriver5.Salutation;
                        //_cardriver.Surname = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver5.SurName));
                        //_cardriver.GivenName = Server.HtmlEncode(General.ClearScriptTag(UsrCarDriver5.GivenName));
                        _cardriver.DOB = UsrCarDriver5.DOB;
                        _cardriver.Gender = UsrCarDriver5.Gender;
                        _cardriver.MaritalStatus = UsrCarDriver5.MaritalStatus;
                        _cardriver.Occupation = UsrCarDriver5.Occupation;
                        _cardriver.JobNature = UsrCarDriver5.JobNature;
                        //_cardriver.IDType = UsrCarDriver5.IDType;
                        //_cardriver.IDNo = UsrCarDriver5.IDNo;
                        _cardriver.YearOfDrivingInSg = UsrCarDriver5.YearsOfDriving;
                        _cardriver.Status = "Active";
                    }
                    _cardriver.ViewedDetailId = Convert.ToInt64(Session[General.ViewedDetailsId].ToString());
                    if (_cardriverdb.Insert(_cardriver) > 0)
                    {
                        _insertcount++;
                    }
                }

                _cardriverdb = null;
                _cardriver = null;

                if (_insertcount == _drivercount)
                {
                    lblMessage.Text += "<br>All drivers are successfully saved!";
                    lblMessage.ForeColor = System.Drawing.Color.Blue;
                }
                else
                {
                    lblMessage.Text += "<br>All drivers are did not saved!";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    return false;
                }
            }
            else
            {
                _cardriverdb.UpdateAllStatus(_carId, _ceuserid);
            }

            _carpolicy = null;
            _carpolicydb = null;
        }

        if (_policyresult > 0)
        {
            //string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("IsCXLive");
            //if (_strCXLive == "1")
            //{
            //    if (CheckFirstTimeQuote())
            //    {
            //        if (!SendMailFirstQuoteToUser())
            //        {
            //            //Account _account = new Account();
            //            //AccountDB _accountdb = new AccountDB();
            //            //_account = _accountdb.GetAccount(Convert.ToInt64(Session[General.UserId].ToString()));
            //            //if (_account.Info1 == "0")
            //            //{
            //            //    _account.Info2 = "First Quote And " + _account.Info2;
            //            //}
            //            //else
            //            //{
            //            //    _account.Info1 = "0";
            //            //    _account.Info2 = "First Quote - Car Insurance";
            //            //}
            //        }
            //    }
            //}
        }
        return _policyresult > 0;
    }

    private void GenerateServerSideCarModel(int CarMakeId)
    {
        CarDetailDB _cardeaildb = new CarDetailDB();
        Int64 _carmakecount = _cardeaildb.GetCarModelCount(CarMakeId);
        DataTable _dtCarModel = _cardeaildb.GetCarModel(CarMakeId);
        if (_dtCarModel != null)
        {
            if (_dtCarModel.Rows.Count > 0)
            {
                int _rowCount = _dtCarModel.Rows.Count;
                for (int i = 0; i < _rowCount; i++)
                {
                }
            }
        }
    }

    private void ChangeValidationEffectServerSide(string strValidationGroup)
    {
        //Year of Manufaturer
        if (rfvManufactYear.Enabled && rfvManufactYear.ValidationGroup == strValidationGroup)
        {
            rfvManufactYear.Validate();
            if (rfvManufactYear.IsValid == false)
            {
                ddlManufactYear.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlManufactYear.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlManufactYear.ControlStyle.CssClass = "";
        }

        if (rfvCheckRegYear.Enabled && rfvCheckRegYear.ValidationGroup == strValidationGroup)
        {
            rfvCheckRegYear.Validate();
            if (rfvCheckRegYear.IsValid == false)
            {
                ddlRegYear.ControlStyle.CssClass = "validationError";
                //lblYesRegYear.ControlStyle.CssClass = "validationError";
                //lblNoRegYear.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlRegYear.ControlStyle.CssClass = "";
                //lblYesRegYear.ControlStyle.CssClass = "";
                //lblNoRegYear.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlRegYear.ControlStyle.CssClass = "";
            //lblYesRegYear.ControlStyle.CssClass = "";
            //lblNoRegYear.ControlStyle.CssClass = "";
        }

        if (rfvRegYear.Enabled && rfvRegYear.ValidationGroup == strValidationGroup)
        {
            rfvRegYear.Validate();
            if (rfvRegYear.IsValid == false)
            {
                ddlRegYear.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlRegYear.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlRegYear.ControlStyle.CssClass = "";
        }

        if (cpvRegYear.Enabled && cpvRegYear.ValidationGroup == strValidationGroup)
        {
            if (rfvRegYear.IsValid)
            {
                cpvRegYear.Validate();
                if (cpvRegYear.IsValid == false)
                {
                    ddlManufactYear.ControlStyle.CssClass = "validationError";
                    ddlRegYear.ControlStyle.CssClass = "validationError";
                    //csvCCFormat.Text = "*";
                }
                else
                {
                    ddlManufactYear.ControlStyle.CssClass = "";
                    ddlRegYear.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            ddlManufactYear.ControlStyle.CssClass = "";
            ddlRegYear.ControlStyle.CssClass = "";
        }

        //Car Model
        if (rfvCustomCarMakeModel.Enabled && rfvCustomCarMakeModel.ValidationGroup == strValidationGroup)
        {
            rfvCustomCarMakeModel.Validate();
            if (rfvCustomCarMakeModel.IsValid == false)
            {
                txtCustomCarMakeModel.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtCustomCarMakeModel.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtCustomCarMakeModel.ControlStyle.CssClass = "";
        }

        //Offpeak
        if (rfvOffPeak.Enabled && rfvOffPeak.ValidationGroup == strValidationGroup)
        {
            rfvOffPeak.Validate();
            if (rfvOffPeak.IsValid == false)
            {
                ddlOffPeak.ControlStyle.CssClass = "validationError";
                //lblYesOffPeak.ControlStyle.CssClass = "validationError";
                //lblNoOffPeak.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlOffPeak.ControlStyle.CssClass = "";
                //lblYesOffPeak.ControlStyle.CssClass = "";
                //lblNoOffPeak.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlOffPeak.ControlStyle.CssClass = "";
            //lblYesOffPeak.ControlStyle.CssClass = "";
            //lblNoOffPeak.ControlStyle.CssClass = "";
        }

        //Cover Commencement Date
        //usrCoverageComDate.ChangeValidationEffectServerSide(strValidationGroup);
        if (rfvCoverComDate.Enabled && rfvCoverComDate.ValidationGroup == strValidationGroup)
        {
            rfvCoverComDate.Validate();
            if (rfvCoverComDate.IsValid == false)
            {
                ddlCoverageComDate.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCoverageComDate.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCoverageComDate.ControlStyle.CssClass = "";
        }

        //Insurance Company
        if (rfvCurInsuranceCompany.Enabled && rfvCurInsuranceCompany.ValidationGroup == strValidationGroup)
        {
            rfvCurInsuranceCompany.Validate();
            if (rfvCurInsuranceCompany.IsValid == false)
            {
                ddlCurInsuranceCompany.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlCurInsuranceCompany.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlCurInsuranceCompany.ControlStyle.CssClass = "";
        }

        //NCD (No Claims Discount) on next renewal
        //if (rfvNCD.Enabled && rfvNCD.ValidationGroup == strValidationGroup)
        //{
        //    rfvNCD.Validate();
        //    if (rfvNCD.IsValid == false)
        //    {
        //        ddlNCD.ControlStyle.CssClass = "validationError";
        //    }
        //    else
        //    {
        //        ddlNCD.ControlStyle.CssClass = "";
        //    }
        //}
        //else
        //{
        //    ddlNCD.ControlStyle.CssClass = "";
        //}

        //Applicable / Renew NCD 
        if (rfvRenewNCD.Enabled && rfvRenewNCD.ValidationGroup == strValidationGroup)
        {
            rfvRenewNCD.Validate();
            if (rfvRenewNCD.IsValid == false)
            {
                ddlRenewNCD.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlRenewNCD.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlRenewNCD.ControlStyle.CssClass = "";
        }

        //Any Claims in the Last 3 Years?
        if (rfvAnyClaim.Enabled && rfvAnyClaim.ValidationGroup == strValidationGroup)
        {
            rfvAnyClaim.Validate();
            if (rfvAnyClaim.IsValid == false)
            {
                ddlClaimLast3Year.ControlStyle.CssClass = "validationError";
                //lblYesClaimLast3Year.ControlStyle.CssClass = "validationError";
                //lblNoClaimLast3Year.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlClaimLast3Year.ControlStyle.CssClass = "";
                //lblYesClaimLast3Year.ControlStyle.CssClass = "";
                //lblNoClaimLast3Year.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlClaimLast3Year.ControlStyle.CssClass = "";
            //lblYesClaimLast3Year.ControlStyle.CssClass = "";
            //lblNoClaimLast3Year.ControlStyle.CssClass = "";
        }

        //No. Of Claim 1
        if (rfvNoOfClaim1.Enabled && rfvNoOfClaim1.ValidationGroup == strValidationGroup)
        {
            rfvNoOfClaim1.Validate();
            if (rfvNoOfClaim1.IsValid == false)
            {
                ddlNoOfClaim1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlNoOfClaim1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlNoOfClaim1.ControlStyle.CssClass = "";
        }

        //Claim Value 1
        if (rfvClaimValue1.Enabled && rfvClaimValue1.ValidationGroup == strValidationGroup)
        {
            rfvClaimValue1.Validate();
            if (rfvClaimValue1.IsValid == false)
            {
                txtClaimValue1.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtClaimValue1.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtClaimValue1.ControlStyle.CssClass = "";
        }

        //No. Of Claim 2
        if (rfvNoOfClaim2.Enabled && rfvNoOfClaim2.ValidationGroup == strValidationGroup)
        {
            rfvNoOfClaim2.Validate();
            if (rfvNoOfClaim2.IsValid == false)
            {
                ddlNoOfClaim2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlNoOfClaim2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlNoOfClaim2.ControlStyle.CssClass = "";
        }

        //Claim Value 2
        if (rfvClaimValue2.Enabled && rfvClaimValue2.ValidationGroup == strValidationGroup)
        {
            rfvClaimValue2.Validate();
            if (rfvClaimValue2.IsValid == false)
            {
                txtClaimValue2.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtClaimValue2.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtClaimValue2.ControlStyle.CssClass = "";
        }

        //No. Of Claim 3
        if (rfvNoOfClaim3.Enabled && rfvNoOfClaim3.ValidationGroup == strValidationGroup)
        {
            rfvNoOfClaim3.Validate();
            if (rfvNoOfClaim3.IsValid == false)
            {
                ddlNoOfClaim3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlNoOfClaim3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlNoOfClaim3.ControlStyle.CssClass = "";
        }

        //Claim Value 3
        if (rfvClaimValue3.Enabled && rfvClaimValue3.ValidationGroup == strValidationGroup)
        {
            rfvClaimValue3.Validate();
            if (rfvClaimValue3.IsValid == false)
            {
                txtClaimValue3.ControlStyle.CssClass = "validationError";
            }
            else
            {
                txtClaimValue3.ControlStyle.CssClass = "";
            }
        }
        else
        {
            txtClaimValue3.ControlStyle.CssClass = "";
        }

        //No Of Claim and Value Custom
        if (csvNoOfClaimAll.Enabled && csvNoOfClaimAll.ValidationGroup == strValidationGroup)
        {
            if (rfvNoOfClaim1.IsValid && rfvNoOfClaim1.IsValid && rfvNoOfClaim1.IsValid)
            {
                csvNoOfClaimAll.Validate();
                if (csvNoOfClaimAll.IsValid == false)
                {
                    ddlNoOfClaim1.ControlStyle.CssClass = "validationError";
                    ddlNoOfClaim2.ControlStyle.CssClass = "validationError";
                    ddlNoOfClaim3.ControlStyle.CssClass = "validationError";
                    //txtClaimValue1.ControlStyle.CssClass = "validationError";
                    //txtClaimValue2.ControlStyle.CssClass = "validationError";
                    //txtClaimValue3.ControlStyle.CssClass = "validationError";
                }
                else
                {
                    ddlNoOfClaim1.ControlStyle.CssClass = "";
                    ddlNoOfClaim2.ControlStyle.CssClass = "";
                    ddlNoOfClaim3.ControlStyle.CssClass = "";

                    //txtClaimValue1.ControlStyle.CssClass = "";
                    //txtClaimValue2.ControlStyle.CssClass = "";
                    //txtClaimValue3.ControlStyle.CssClass = "";
                }
            }
        }
        else
        {
            ddlNoOfClaim1.ControlStyle.CssClass = "";
            ddlNoOfClaim2.ControlStyle.CssClass = "";
            ddlNoOfClaim3.ControlStyle.CssClass = "";
            //txtClaimValue1.ControlStyle.CssClass = "";
            //txtClaimValue2.ControlStyle.CssClass = "";
            //txtClaimValue3.ControlStyle.CssClass = "";
        }

        //Offence-Free Driving/COM
        if (rfvOffenceFDCom.Enabled && rfvOffenceFDCom.ValidationGroup == strValidationGroup)
        {
            rfvOffenceFDCom.Validate();
            if (rfvOffenceFDCom.IsValid == false)
            {
                ddlOffFDCom.ControlStyle.CssClass = "validationError";
                //lblYesOffFDCom.ControlStyle.CssClass = "validationError";
                //lblNoOffFDCom.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlOffFDCom.ControlStyle.CssClass = "";
                //lblYesOffFDCom.ControlStyle.CssClass = "";
                //lblNoOffFDCom.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlOffFDCom.ControlStyle.CssClass = "";
            //lblYesOffFDCom.ControlStyle.CssClass = "";
            //lblNoOffFDCom.ControlStyle.CssClass = "";
        }


        //Add Additional Name Driver
        if (rfvAddDriver.Enabled && rfvAddDriver.ValidationGroup == strValidationGroup)
        {
            rfvAddDriver.Validate();
            if (rfvAddDriver.IsValid == false)
            {
                ddlAddDriver.ControlStyle.CssClass = "validationError";
                //lblYesAddDriver.ControlStyle.CssClass = "validationError";
                //lblNoAddDriver.ControlStyle.CssClass = "validationError";
            }
            else
            {
                ddlOffFDCom.ControlStyle.CssClass = "";
                //lblYesAddDriver.ControlStyle.CssClass = "";
                //lblNoAddDriver.ControlStyle.CssClass = "";
            }
        }
        else
        {
            ddlOffFDCom.ControlStyle.CssClass = "";
            //lblYesAddDriver.ControlStyle.CssClass = "";
            //lblNoAddDriver.ControlStyle.CssClass = "";
        }

        //View My Result By Sorting
        //if (rfvSortBy.Enabled && rfvSortBy.ValidationGroup == strValidationGroup)
        //{
        //    rfvSortBy.Validate();
        //    if (rfvSortBy.IsValid == false)
        //    {
        //        ddlSortBy.ControlStyle.CssClass = "validationError";
        //    }
        //    else
        //    {
        //        ddlSortBy.ControlStyle.CssClass = "";
        //    }
        //}
        //else
        //{
        //    ddlSortBy.ControlStyle.CssClass = "";
        //}

        //Car Driver
        UsrCarDriver1.ChangeValidationEffectServerSide("cardetail");
        UsrCarDriver2.ChangeValidationEffectServerSide("cardetail");
        UsrCarDriver3.ChangeValidationEffectServerSide("cardetail");
        UsrCarDriver4.ChangeValidationEffectServerSide("cardetail");
        UsrCarDriver5.ChangeValidationEffectServerSide("cardetail");
    }


    private void GenerateCarModel(int CarMakeId, string CarMakeDesc)
    {
        CarDetailDB _cardeaildb = new CarDetailDB();
        DataTable _dtCarModel = new DataTable("CarTable");
        _dtCarModel = _cardeaildb.GetCarModelAndOthers(CarMakeId);

        //string _strCXLive = CE.Configuration.MyConfigurationManager.GetAppSettingValue("IsCXLive");
        //if (_strCXLive == "0")
        //{
        //    _dtCarModel = _cardeaildb.GetCarModelAndOthers(CarMakeId);
        //}
        //else
        //{
        //    _dtCarModel = _cardeaildb.GetCarModel(CarMakeId);
        //}

        //if (_strCXLive == "0")
        //{
        //    DataTable _dtCarModelOthers = _cardeaildb.GetCarModelOthers(CarMakeId);
        //    for (int i = 0; i < _dtCarModelOthers.Rows.Count; i++)
        //    {
        //        DataRow _drTemp = _dtCarModel.NewRow();
        //        _drTemp[0] = _dtCarModelOthers.Rows[i][0];
        //        _drTemp[1] = _dtCarModelOthers.Rows[i][1];
        //        _drTemp[2] = _dtCarModelOthers.Rows[i][2];
        //        _drTemp[3] = _dtCarModelOthers.Rows[i][3];
        //        _dtCarModel.Rows.Add(_drTemp);
        //    }
        //}
        ddlCarModel.Items.Clear();
        ddlCarModel.Items.Add(new ListItem("Select", "-1"));
        string _tempModelDesc = "";
        if (_dtCarModel != null && _dtCarModel.Rows.Count > 0)
        {
            for (int i = 0; i < _dtCarModel.Rows.Count; i++)
            {
                _tempModelDesc = _dtCarModel.Rows[i][1].ToString();
                _tempModelDesc = _tempModelDesc.Replace(CarMakeDesc, "");
                _tempModelDesc = _tempModelDesc.Trim();
                _tempModelDesc = _tempModelDesc + " " + _dtCarModel.Rows[i][2].ToString() + " " + _dtCarModel.Rows[i][3].ToString() + "cc";
                ddlCarModel.Items.Add(new ListItem(_tempModelDesc, _dtCarModel.Rows[i][0].ToString()));
            }
        }
    }
    private void GenerateCarMakeModel()
    {
        CarDetailDB _cardeaildb = new CarDetailDB();

        DataTable _dtCarModel = _cardeaildb.GetAllCarModel();

        Int64 _carmakecount = _dtCarModel.Rows.Count;

        string strCarModelDesc = "";
        System.Text.StringBuilder _scriptCarMakeModelList = new System.Text.StringBuilder();
        _scriptCarMakeModelList.Append("<script type='text/javascript'>var CarMakeModelList = [");
        if (_dtCarModel != null)
        {
            if (_dtCarModel.Rows.Count > 0)
            {
                int _rowCount = _dtCarModel.Rows.Count;
                for (int i = 0; i < _rowCount; i++)
                {
                    strCarModelDesc = Server.HtmlDecode(_dtCarModel.Rows[i][2].ToString().Trim()).Replace("\"", "'") + " " + Server.HtmlDecode(_dtCarModel.Rows[i][3].ToString().Trim()).Replace("\"", "'") + " " + Server.HtmlDecode(_dtCarModel.Rows[i][4].ToString().Trim()).Replace("\"", "'") + "cc";
                    _scriptCarMakeModelList.Append("{makeid:'" + _dtCarModel.Rows[i][0].ToString() + "',modelid:'" + _dtCarModel.Rows[i][1].ToString() + "',desc:'" + strCarModelDesc + "'},");

                }
                _scriptCarMakeModelList.Append("{makeid:'',modelid:'',desc:''}];</script>");
                ScriptManager.RegisterClientScriptBlock(Page, this.GetType(), "PageCarMakeModelList", _scriptCarMakeModelList.ToString(), false);
            }

        }
    }

    //CAR POLICY DETAILS
    protected void CheckAllNoOfClaim(object source, ServerValidateEventArgs args)
    {
        if (ddlNoOfClaim1.Text == "-1" && ddlNoOfClaim2.Text == "-1" && ddlNoOfClaim3.Text == "-1")
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }

    protected void CheckClaimValue1(object source, ServerValidateEventArgs args)
    {
        if (ddlNoOfClaim1.Text != "-1" && (Convert.ToInt32(txtClaimValue1.Text.Trim()) <= 0))
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }

    protected void CheckClaimValue2(object source, ServerValidateEventArgs args)
    {
        if (ddlNoOfClaim2.Text != "-1" && (Convert.ToInt32(txtClaimValue2.Text.Trim()) <= 0))
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }

    protected void CheckClaimValue3(object source, ServerValidateEventArgs args)
    {
        if (ddlNoOfClaim3.Text != "-1" && (Convert.ToInt32(txtClaimValue3.Text.Trim()) <= 0))
        {
            args.IsValid = false;
        }
        else
        {
            args.IsValid = true;
        }
    }

    protected void DriverFieldValidate(object source, ServerValidateEventArgs args)
    {
        if (txtDriverValid.Text.ToLower() == "valid")
            args.IsValid = true;
        else
            args.IsValid = false;
    }

    private void ShowPolicyDetail(Int64 CarId, Int64 PolicyId, Int64 UserId)
    {
        CarPolicy _carpolicy = new CarPolicy();
        CarPolicyDB _carpolicydb = new CarPolicyDB();
        _carpolicy = _carpolicydb.GetCarPolicy(CarId, PolicyId, UserId);
        if (_carpolicy != null)
        {
            SetProperty(_carpolicy);
        }
        _carpolicy = null;
        _carpolicydb = null;
    }

    private void SetProperty(CarPolicy _CarPolicy)
    {
        //ddlCoverageComDate.Text = _CarPolicy.CoverageCommenceDate.Day.ToString("00") + "/" + _CarPolicy.CoverageCommenceDate.Month.ToString("00") + "/" + _CarPolicy.CoverageCommenceDate.Year.ToString("0000");
        ddlCoverageComDate.Text = _CarPolicy.CoverageCommenceDate.Day.ToString("00") + _CarPolicy.CoverageCommenceDate.Month.ToString("00") + _CarPolicy.CoverageCommenceDate.Year.ToString("0000");

        DateTime _dtNow = new DateTime(CE.Global.General.GetUTCDateTime().Year, CE.Global.General.GetUTCDateTime().Month, CE.Global.General.GetUTCDateTime().Day);

        if (_CarPolicy.CoverageCommenceDate >= _dtNow)
        {
            DateTime _dtCommDate = _CarPolicy.CoverageCommenceDate;
            _dtCommDate = _dtCommDate.AddDays(-1);
            _dtCommDate = _dtCommDate.AddYears(1);
            lblCoverageExpireDate.Text = _dtCommDate.ToString("dd/MMMM/yyyy");
        }
        //usrCoverageComDate.Day = _CarPolicy.CoverageCommenceDate.Day;
        //usrCoverageComDate.Month = _CarPolicy.CoverageCommenceDate.Month;
        //usrCoverageComDate.Year = _CarPolicy.CoverageCommenceDate.Year;

        //ddlNCD.Text = _CarPolicy.NCDPercent.ToString();

        //if (ddlRenewNCD.Text == "50")
        //{
        //    if (_CarPolicy.Info2 != null && _CarPolicy.Info2 != "-1")
        //    {
        //        divNCDYear.Visible = true;
        //        ddlNCDYear.Text = _CarPolicy.Info2;
        //    }
        //}

        //rdoYesClaimLast3Year.Checked = _CarPolicy.IsClaimLastThreeYear;
        //rdoNoClaimLast3Year.Checked = !_CarPolicy.IsClaimLastThreeYear;
        ddlClaimLast3Year.Text = _CarPolicy.IsClaimLastThreeYear ? "1" : "0";
        //Claim_Change(null, null);
        ddlClaimLast3Year_SelectedIndexChanged(null, null);

        //rdoYesOffFDCom.Checked = _CarPolicy.IsOffDriveCom;
        //rdoNoOffFDCom.Checked = !_CarPolicy.IsOffDriveCom;
        ddlOffFDCom.Text = _CarPolicy.IsOffDriveCom ? "1" : "0";

        //rdoYesAddDriver.Checked = _CarPolicy.IsAddDriver;
        //rdoNoAddDriver.Checked = !_CarPolicy.IsAddDriver;
        ddlAddDriver.Text = _CarPolicy.IsAddDriver ? "1" : "0";
        ddlDriverCount.Text = _CarPolicy.NoOfDriver.ToString();
        if (ddlClaimLast3Year.Text == "1")
        {
            CarClaimHistory _carclaimhistory = new CarClaimHistory();
            CarClaimHistoryDB _carclaimhistorydb = new CarClaimHistoryDB();
            _carclaimhistory = _carclaimhistorydb.GetCarClaimHistory(_CarPolicy.CECarId, _CarPolicy.RefCEUserId);
            if (_carclaimhistory != null)
            {
                Session[General.CarClaimHistoryId] = _carclaimhistory.CarClaimId.ToString();

                ddlNoOfClaim3.Text = _carclaimhistory.NoOfClaimInLast3Year.ToString();
                ddlNoOfClaim2.Text = _carclaimhistory.NoOfClaimInLast2Year.ToString();
                ddlNoOfClaim1.Text = _carclaimhistory.NoOfClaimInLast1Year.ToString();

                txtClaimValue3.Text = _carclaimhistory.Last3YearClaimValue.ToString();
                txtClaimValue2.Text = _carclaimhistory.Last2YearClaimValue.ToString();
                txtClaimValue1.Text = _carclaimhistory.Last1YearClaimValue.ToString();

                this.CheckClaim(this, null);
            }
        }

        if (_CarPolicy.NCDPercent == 50 && _CarPolicy.Info1 == "50")
            ddlRenewNCD.Text = "60";
        else
            ddlRenewNCD.Text = _CarPolicy.Info1;

        if (_CarPolicy.NoOfDriver > 0 && ddlAddDriver.Text == "1")
        {
            divAddDriver.Visible = true;
            pnlDriver.Visible = true;
            //txtAddDriver.Text = "1";

            int _noOfDriver = _CarPolicy.NoOfDriver;
            CarDriverList _cardriverlist = new CarDriverList();
            CarDriverDB _cardriverdb = new CarDriverDB();
            _cardriverlist = _cardriverdb.GetCarDriverList(_CarPolicy.CECarId, _CarPolicy.RefCEUserId);
            _cardriverdb = null;

            for (int i = 1; i <= _noOfDriver; i++)
            {
                CarDriver _cardriver = _cardriverlist[i - 1];
                if (i == 1)
                {
                    //Response.Write("<script type='text/javascript'>alert('" + _cardriver.Surname + "');</script>");
                    UsrCarDriver1.DriverId = _cardriver.CarDriverId;
                    //UsrCarDriver1.Salutation = _cardriver.Salutation;
                    //UsrCarDriver1.SurName = Server.HtmlDecode(_cardriver.Surname);
                    //UsrCarDriver1.GivenName = Server.HtmlDecode(_cardriver.GivenName);
                    UsrCarDriver1.Gender = _cardriver.Gender;
                    UsrCarDriver1.MaritalStatus = _cardriver.MaritalStatus;
                    UsrCarDriver1.DOB = _cardriver.DOB;
                    //UsrCarDriver1.IDType = _cardriver.IDType;
                    //UsrCarDriver1.IDNo = _cardriver.IDNo;
                    UsrCarDriver1.Occupation = _cardriver.Occupation;
                    UsrCarDriver1.JobNature = _cardriver.JobNature;
                    UsrCarDriver1.YearsOfDriving = _cardriver.YearOfDrivingInSg;
                    UsrCarDriver1.IsEnabled = true;
                    //UsrCarDriver1.SetProperty();
                }
                else if (i == 2)
                {
                    UsrCarDriver2.DriverId = _cardriver.CarDriverId;
                    //UsrCarDriver2.Salutation = _cardriver.Salutation;
                    //UsrCarDriver2.SurName = Server.HtmlDecode(_cardriver.Surname);
                    //UsrCarDriver2.GivenName = Server.HtmlDecode(_cardriver.GivenName);
                    UsrCarDriver2.Gender = _cardriver.Gender;
                    UsrCarDriver2.MaritalStatus = _cardriver.MaritalStatus;
                    UsrCarDriver2.DOB = _cardriver.DOB;
                    //UsrCarDriver2.IDType = _cardriver.IDType;
                    //UsrCarDriver2.IDNo = _cardriver.IDNo;
                    UsrCarDriver2.Occupation = _cardriver.Occupation;
                    UsrCarDriver2.JobNature = _cardriver.JobNature;
                    UsrCarDriver2.YearsOfDriving = _cardriver.YearOfDrivingInSg;
                    UsrCarDriver2.IsEnabled = true;
                    //UsrCarDriver2.SetProperty();
                }
                else if (i == 3)
                {
                    UsrCarDriver3.DriverId = _cardriver.CarDriverId;
                    //UsrCarDriver3.Salutation = _cardriver.Salutation;
                    //UsrCarDriver3.SurName = Server.HtmlDecode(_cardriver.Surname);
                    //UsrCarDriver3.GivenName = Server.HtmlDecode(_cardriver.GivenName);
                    UsrCarDriver3.Gender = _cardriver.Gender;
                    UsrCarDriver3.MaritalStatus = _cardriver.MaritalStatus;
                    UsrCarDriver3.DOB = _cardriver.DOB;
                    //UsrCarDriver3.IDType = _cardriver.IDType;
                    //UsrCarDriver3.IDNo = _cardriver.IDNo;
                    UsrCarDriver3.Occupation = _cardriver.Occupation;
                    UsrCarDriver3.JobNature = _cardriver.JobNature;
                    UsrCarDriver3.YearsOfDriving = _cardriver.YearOfDrivingInSg;
                    UsrCarDriver3.IsEnabled = true;
                    //UsrCarDriver3.SetProperty();
                }
                else if (i == 4)
                {
                    UsrCarDriver4.DriverId = _cardriver.CarDriverId;
                    //UsrCarDriver4.Salutation = _cardriver.Salutation;
                    //UsrCarDriver4.SurName = Server.HtmlDecode(_cardriver.Surname);
                    //UsrCarDriver4.GivenName = Server.HtmlDecode(_cardriver.GivenName);
                    UsrCarDriver4.Gender = _cardriver.Gender;
                    UsrCarDriver4.MaritalStatus = _cardriver.MaritalStatus;
                    UsrCarDriver4.DOB = _cardriver.DOB;
                    //UsrCarDriver4.IDType = _cardriver.IDType;
                    //UsrCarDriver4.IDNo = _cardriver.IDNo;
                    UsrCarDriver4.Occupation = _cardriver.Occupation;
                    UsrCarDriver4.JobNature = _cardriver.JobNature;
                    UsrCarDriver4.YearsOfDriving = _cardriver.YearOfDrivingInSg;
                    UsrCarDriver4.IsEnabled = true;
                    //UsrCarDriver4.SetProperty();
                }
                else if (i == 5)
                {
                    UsrCarDriver5.DriverId = _cardriver.CarDriverId;
                    //UsrCarDriver5.Salutation = _cardriver.Salutation;
                    //UsrCarDriver5.SurName = Server.HtmlDecode(_cardriver.Surname);
                    //UsrCarDriver5.GivenName = Server.HtmlDecode(_cardriver.GivenName);
                    UsrCarDriver5.Gender = _cardriver.Gender;
                    UsrCarDriver5.MaritalStatus = _cardriver.MaritalStatus;
                    UsrCarDriver5.DOB = _cardriver.DOB;
                    //UsrCarDriver5.IDType = _cardriver.IDType;
                    //UsrCarDriver5.IDNo = _cardriver.IDNo;
                    UsrCarDriver5.Occupation = _cardriver.Occupation;
                    UsrCarDriver5.JobNature = _cardriver.JobNature;
                    UsrCarDriver5.YearsOfDriving = _cardriver.YearOfDrivingInSg;
                    UsrCarDriver5.IsEnabled = true;
                    //UsrCarDriver5.SetProperty();
                }
            }
            _cardriverlist = null;
        }
        else
        {
            pnlDriver.Visible = false;
            divAddDriver.Visible = false;
            //txtAddDriver.Text = "1";
        }
    }

    private void DriverSetting()
    {
        if (ddlDriverCount.SelectedValue != "-1" && ddlAddDriver.Text == "1")
        {
            int _drivercount = Convert.ToInt32(ddlDriverCount.SelectedValue);
            for (int i = 1; i <= 5; i++)
            {
                string strDivName = "divDriver" + i.ToString();
                HtmlGenericControl _divDriver = (HtmlGenericControl)pnlDriver.FindControl(strDivName);
                //string strUsrDriver = "UsrCarDriver" + i.ToString();
                //controls_usrCarDriverDetails _ctrlDriver = (controls_usrCarDriverDetails)pnlDriver.FindControl(strUsrDriver);
                if (i > _drivercount)
                {
                    if (_divDriver != null)
                    {
                        _divDriver.Visible = false;
                        //_ctrlDriver.Visible = false;
                    }
                }
                else
                {
                    if (_divDriver != null)
                    {
                        _divDriver.Visible = true;
                        //_ctrlDriver.Visible = true;
                    }
                }
            }

            /*
            for (int i = 1; i <= 5; i++)
            {
                string strCtrlName = "UsrCarDriver" + i.ToString();
                controls_usrCarDriverDetails ctrlDriver = (controls_usrCarDriverDetails)pnlDriver.FindControl(strCtrlName);
                if (ctrlDriver != null)
                {
                    ctrlDriver.IsEnableValidation(false);
                }
            }

            for (int i = _drivercount; i >= 1; i--)
            {
                string strCtrlName = "UsrCarDriver" + i.ToString();
                controls_usrCarDriverDetails ctrlDriver = (controls_usrCarDriverDetails)pnlDriver.FindControl(strCtrlName);
                if (ctrlDriver != null)
                {
                    ctrlDriver.Visible = true;
                }
            }
            */
        }
        else
        {
            for (int i = 1; i <= 5; i++)
            {
                string strDivName = "divDriver" + i.ToString();
                HtmlGenericControl _divDriver = (HtmlGenericControl)pnlDriver.FindControl(strDivName);
                string strUsrDriver = "UsrCarDriver" + i.ToString();
                controls_usrCarDriverDetails _ctrlDriver = (controls_usrCarDriverDetails)pnlDriver.FindControl(strUsrDriver);
                if (_divDriver != null && _ctrlDriver != null)
                {
                    _divDriver.Visible = false;
                    _ctrlDriver.ClearProperty();
                    _ctrlDriver.IsEnableValidation(false);
                }

            }
        }
    }

    private void OtherValidation()
    {
        CheckCustomCarMakeModel(chkCannotfind.Checked);
        //if (rdoYesClaimLast3Year.Checked == false && rdoNoClaimLast3Year.Checked == false)
        //{
        //    rfvAnyClaim.IsValid = false;
        //}
        //else
        //{
        //    txtAnyClaim.Text = "1";
        //    rfvAnyClaim.Validate();
        //}

        //if (rdoYesOffFDCom.Checked == false && rdoNoOffFDCom.Checked == false)
        //{
        //    rfvOffenceFDCom.IsValid = false;
        //}
        //else
        //{
        //    txtOffenceFree.Text = "1";
        //    rfvOffenceFDCom.Validate();
        //}

        //if (rdoYesAddDriver.Checked == false && rdoNoAddDriver.Checked == false)
        //{
        //    rfvAddDriver.IsValid = false;
        //}
        //else
        //{
        //    txtAddDriver.Text = "1";
        //    rfvAddDriver.Validate();
        //}

        if (ddlClaimLast3Year.Text == "1")
        {
            divAnyClaim.Style.Value = ""; ;

            rfvNoOfClaim3.Enabled = true;
            rfvNoOfClaim2.Enabled = true; /// NO NEED
            rfvNoOfClaim1.Enabled = true; /// NO NEED
            csvNoOfClaimAll.Enabled = true;                               /// 
            if (Convert.ToInt32(ddlNoOfClaim3.SelectedValue) > 0)
            {
                rfvClaimValue3.Enabled = true;
                revClaimValue3.Enabled = true;
            }
            else
            {
                rfvClaimValue3.Enabled = false;
                revClaimValue3.Enabled = false;
            }

            if (Convert.ToInt32(ddlNoOfClaim2.SelectedValue) > 0)
            {
                rfvClaimValue2.Enabled = true;
                revClaimValue2.Enabled = true;
            }
            else
            {
                rfvClaimValue2.Enabled = false;
                revClaimValue2.Enabled = false;
            }

            if (Convert.ToInt32(ddlNoOfClaim1.SelectedValue) > 0)
            {
                rfvClaimValue1.Enabled = true;
                revClaimValue1.Enabled = true;
            }
            else
            {
                rfvClaimValue1.Enabled = false;
                revClaimValue1.Enabled = false;
            }

            if (Convert.ToInt32(ddlNoOfClaim1.SelectedValue) > 0 ||
               Convert.ToInt32(ddlNoOfClaim2.SelectedValue) > 0 ||
                Convert.ToInt32(ddlNoOfClaim3.SelectedValue) > 0)
            {
                if (Convert.ToInt32(ddlNoOfClaim1.SelectedValue) < 0)
                {
                    ddlNoOfClaim1.Text = "-1";
                    //ddlClaimValue1.Text = "-1";
                    txtClaimValue1.Text = "";
                    rfvNoOfClaim1.Enabled = false;
                    rfvClaimValue1.Enabled = false;
                    revClaimValue1.Enabled = false;

                }

                if (Convert.ToInt32(ddlNoOfClaim2.SelectedValue) < 0)
                {
                    ddlNoOfClaim2.Text = "-1";
                    //ddlClaimValue2.Text = "-1";
                    txtClaimValue2.Text = "";
                    rfvNoOfClaim2.Enabled = false;
                    rfvClaimValue2.Enabled = false;
                    revClaimValue2.Enabled = false;
                }

                if (Convert.ToInt32(ddlNoOfClaim3.SelectedValue) < 0)
                {
                    ddlNoOfClaim3.Text = "-1";
                    //ddlClaimValue3.Text = "-1";
                    txtClaimValue3.Text = "";
                    rfvNoOfClaim3.Enabled = false;
                    rfvClaimValue3.Enabled = false;
                    revClaimValue3.Enabled = false;
                }
            }

        }
        else
        {
            //divAddDriver.Style.Value = "display:none"; ;
            csvNoOfClaimAll.Enabled = false;
            rfvNoOfClaim3.Enabled = false;
            rfvClaimValue3.Enabled = false;
            revClaimValue3.Enabled = false;
            rfvClaimValue2.Enabled = false;
            revClaimValue2.Enabled = false;
            rfvClaimValue1.Enabled = false;
            revClaimValue1.Enabled = false;
            rfvNoOfClaim2.Enabled = false;
            rfvNoOfClaim1.Enabled = false;
        }
    }

    private bool DriverValidation()
    {
        //String[] ArrDriver;
        //bool _result = true;
        //lblMessage.Text = "";
        //if (ddlDriverCount.SelectedValue != "-1")
        //{
        //    int _drivercount = Convert.ToInt32(ddlDriverCount.SelectedValue);
        //    divAddDriver.Visible = false;

        //    ArrDriver = new String[_drivercount + 1];
        //    for (int i = 1; i <= 5; i++)
        //    {
        //        string strCtrlName = "UsrCarDriver" + i.ToString();
        //        string strDivDriverName = "divDriver" + i.ToString();
        //        controls_usrCarDriverDetails ctrlDriver = (controls_usrCarDriverDetails)pnlDriver.FindControl(strCtrlName);
        //        HtmlGenericControl divCtrl = (HtmlGenericControl)pnlDriver.FindControl(strDivDriverName);
        //        if (divCtrl != null)
        //        {
        //            divCtrl.Visible = false;
        //        }

        //        if (ctrlDriver != null)
        //        {
        //            ctrlDriver.IsEnableValidation(false);
        //        }
        //        if (i <= _drivercount)
        //        {
        //            ArrDriver[i] = "";
        //        }
        //    }

        //    if (rdoYesAddDriver.Checked)
        //    {
        //        divAddDriver.Style.Value = ""; ;
        //        ddlDriverCount.Enabled = true;
        //        for (int i = _drivercount; i >= 1; i--)
        //        {
        //            string strCtrlName = "UsrCarDriver" + i.ToString();
        //            string strDivDriverName = "divDriver" + i.ToString();
        //            controls_usrCarDriverDetails ctrlDriver = (controls_usrCarDriverDetails)pnlDriver.FindControl(strCtrlName);
        //            HtmlGenericControl divCtrl = (HtmlGenericControl)pnlDriver.FindControl(strDivDriverName);
        //            if (divCtrl != null)
        //            {
        //                divCtrl.Visible = true;
        //            }

        //            if (ctrlDriver != null)
        //            {

        //                ctrlDriver.IsEnableValidation(true);

        //                ctrlDriver.ClearProperty();
        //                ctrlDriver.SetProperty();

        //            }
        //        }


        //        for (int i = 1; i <= _drivercount; i++)
        //        {
        //            string IdNo = "";
        //            IdNo = ArrDriver[i].ToString();
        //            if (IdNo.Length < 9) continue;

        //            for (int j = _drivercount; j > i; j--)
        //            {
        //                if (IdNo == ArrDriver[j])
        //                {
        //                    if (j == _drivercount && i == 1 && csvDriver.ErrorMessage.Length == 0)
        //                    {
        //                        csvDriver.ErrorMessage += "Driver " + i.ToString() + "'s ID Number should not same with Driver " + j.ToString() + "'s ID Number.";
        //                    }
        //                    else
        //                    {
        //                        csvDriver.ErrorMessage += "<li>Driver " + i.ToString() + "'s ID Number should not same with Driver " + j.ToString() + "'s ID Number.</li>";
        //                    }
        //                    //lblMessage.Text += "Driver " + (i + 1).ToString() + "'s ID Number should not same with Driver  " + (j + 1).ToString() + "'s ID Number.<br/>";
        //                    _result = false;
        //                }
        //            }
        //        }
        //    }

        //}
        //return _result;
        return true;
    }

    private bool CheckClaimValue()
    {
        bool ClaimValue = true;
        //if (rdoYesClaimLast3Year.Checked == true)
        //{
        //    if ((ddlNoOfClaim3.SelectedIndex > 0) && (Convert.ToInt32(txtClaimValue3.Text.Trim()) <= 0))
        //    {
        //        ClaimValue = false;
        //    }
        //    else if ((ddlNoOfClaim2.SelectedIndex > 0) && (Convert.ToInt32(txtClaimValue2.Text.Trim()) <= 0))
        //    {
        //        ClaimValue = false;
        //    }
        //    else if ((ddlNoOfClaim1.SelectedIndex > 0) && (Convert.ToInt32(txtClaimValue1.Text.Trim()) <= 0))
        //    {
        //        ClaimValue = false;
        //    }
        //}
        return ClaimValue;
    }

    private int GetExistingNCD()
    {
        int ExistingNCD = 0;

        if (ddlRenewNCD.Text == "0")
            ExistingNCD = -1;
        else
            ExistingNCD = Convert.ToInt32(ddlRenewNCD.Text) - 10;
        return ExistingNCD;
    }

    protected void ddlAddDriver_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAddDriver.Text == "1")
        {
            pnlDriver.Visible = true;
            divAddDriver.Visible = true;
            ddlDriverCount.Text = "1";
            DriverSetting();
        }
        else
        {
            pnlDriver.Visible = false;
            divAddDriver.Visible = false;
            DriverSetting();
        }
    }

    protected void rdoYesAddDriver_CheckedChanged(object sender, EventArgs e)
    {

        //if (rdoYesAddDriver.Checked)
        //{
        //    txtAddDriver.Text = "1";
        //    pnlDriver.Visible = true;
        //    divAddDriver.Visible = true;
        //    ddlDriverCount.Text = "1";

        //    DriverSetting();
        //}
    }

    protected void rdoNoAddDriver_CheckedChanged(object sender, EventArgs e)
    {
        //Claim_Change(sender, e);
        //if (rdoNoAddDriver.Checked)
        //{
        //    txtAddDriver.Text = "1";
        //    pnlDriver.Visible = false;
        //    divAddDriver.Visible = false;
        //    DriverSetting();
        //}
    }

    protected void rdoNoCliam_CheckChange(object sender, EventArgs e)
    {
        //Claim_Change(sender, e);

        //ddlRenewNCD.Items.Clear();
        //ddlRenewNCD.Items.Add(new ListItem("Select", "-1"));
        //ddlRenewNCD.Items.Add(new ListItem("0", "0"));
        //ddlRenewNCD.Items.Add(new ListItem("10", "10"));
        //ddlRenewNCD.Items.Add(new ListItem("20", "20"));
        //ddlRenewNCD.Items.Add(new ListItem("30", "30"));
        //ddlRenewNCD.Items.Add(new ListItem("40", "40"));
        //ddlRenewNCD.Items.Add(new ListItem("50% (1st year)", "50"));
        //ddlRenewNCD.Items.Add(new ListItem("50% (> one year)", "60"));
    }

    protected void rdoYesCliam_CheckChange(object sender, EventArgs e)
    {
        //Claim_Change(sender, e);
    }

    protected void ddlClaimLast3Year_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlClaimLast3Year.Text == "1")
        {
            divAnyClaim.Visible = true;
            rfvNoOfClaim1.Enabled = true;
            rfvNoOfClaim2.Enabled = true;
            rfvNoOfClaim3.Enabled = true;

            rfvClaimValue1.Enabled = true;
            rfvClaimValue2.Enabled = true;
            rfvClaimValue3.Enabled = true;

            revClaimValue1.Enabled = true;
            revClaimValue2.Enabled = true;
            revClaimValue3.Enabled = true;
        }
        else
        {
            divAnyClaim.Visible = false;
            rfvNoOfClaim1.Enabled = false;
            rfvNoOfClaim2.Enabled = false;
            rfvNoOfClaim3.Enabled = false;

            rfvClaimValue1.Enabled = false;
            rfvClaimValue2.Enabled = false;
            rfvClaimValue3.Enabled = false;

            revClaimValue1.Enabled = false;
            revClaimValue2.Enabled = false;
            revClaimValue3.Enabled = false;

            ddlNoOfClaim1.Text = "-1";
            ddlNoOfClaim2.Text = "-1";
            ddlNoOfClaim3.Text = "-1";
            txtClaimValue1.Text = "";
            txtClaimValue2.Text = "";
            txtClaimValue3.Text = "";

            ddlRenewNCD.Items.Clear();
            ddlRenewNCD.Items.Add(new ListItem("Select", "-1"));
            ddlRenewNCD.Items.Add(new ListItem("0", "0"));
            ddlRenewNCD.Items.Add(new ListItem("10", "10"));
            ddlRenewNCD.Items.Add(new ListItem("20", "20"));
            ddlRenewNCD.Items.Add(new ListItem("30", "30"));
            ddlRenewNCD.Items.Add(new ListItem("40", "40"));
            ddlRenewNCD.Items.Add(new ListItem("50% (1st year)", "50"));
            ddlRenewNCD.Items.Add(new ListItem("50% (> one year)", "60"));
        }
    }

    protected void Claim_Change(object sender, EventArgs e)
    {
        //if (rdoYesClaimLast3Year.Checked == false)
        //{
        //    divAnyClaim.Visible = false;
        //    txtAnyClaim.Text = "1";
        //    rfvNoOfClaim1.Enabled = false;
        //    rfvNoOfClaim2.Enabled = false;
        //    rfvNoOfClaim3.Enabled = false;

        //    rfvClaimValue1.Enabled = false;
        //    rfvClaimValue2.Enabled = false;
        //    rfvClaimValue3.Enabled = false;

        //    revClaimValue1.Enabled = false;
        //    revClaimValue2.Enabled = false;
        //    revClaimValue3.Enabled = false;

        //    ddlNoOfClaim1.Text = "-1";
        //    ddlNoOfClaim2.Text = "-1";
        //    ddlNoOfClaim3.Text = "-1";
        //    txtClaimValue1.Text = "";
        //    txtClaimValue2.Text = "";
        //    txtClaimValue3.Text = "";
        //}
        //else if (rdoYesClaimLast3Year.Checked == true)
        //{
        //    divAnyClaim.Visible = true;
        //    txtAnyClaim.Text = "1";
        //    rfvNoOfClaim1.Enabled = true;
        //    rfvNoOfClaim2.Enabled = true;
        //    rfvNoOfClaim3.Enabled = true;

        //    rfvClaimValue1.Enabled = true;
        //    rfvClaimValue2.Enabled = true;
        //    rfvClaimValue3.Enabled = true;

        //    revClaimValue1.Enabled = true;
        //    revClaimValue2.Enabled = true;
        //    revClaimValue3.Enabled = true;
        //}
    }

    //protected void ddlNCD_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    divNCDYear.Visible = false;
    //    ddlRenewNCD.Enabled = true;
    //    ddlRenewNCD.Items.Clear();
    //    int _curNCD = Convert.ToInt32(ddlNCD.Text);

    //    if (_curNCD == -1)
    //    {
    //        rdoYesClaimLast3Year.Checked = false;
    //        rdoNoClaimLast3Year.Checked = true;
    //    }

    //    if (rdoYesClaimLast3Year.Checked == false)
    //    {
    //        if (_curNCD == -1)
    //        {
    //            ddlRenewNCD.Items.Add(new ListItem("0", "0"));
    //        }
    //        else if (_curNCD == 0)
    //        {
    //            ddlRenewNCD.Items.Add(new ListItem("0", "0"));
    //            ddlRenewNCD.Items.Add(new ListItem("10", "10"));
    //            ddlRenewNCD.Text = "10";
    //        }
    //        else if (_curNCD == 10)
    //        {
    //            ddlRenewNCD.Items.Add(new ListItem("10", "10"));
    //            ddlRenewNCD.Items.Add(new ListItem("20", "20"));
    //            ddlRenewNCD.Text = "20";
    //        }
    //        else if (_curNCD == 20)
    //        {
    //            ddlRenewNCD.Items.Add(new ListItem("20", "20"));
    //            ddlRenewNCD.Items.Add(new ListItem("30", "30"));
    //            ddlRenewNCD.Text = "30";
    //        }
    //        else if (_curNCD == 30)
    //        {
    //            ddlRenewNCD.Items.Add(new ListItem("30", "30"));
    //            ddlRenewNCD.Items.Add(new ListItem("40", "40"));
    //            ddlRenewNCD.Text = "40";
    //        }
    //        else if (_curNCD == 40)
    //        {
    //            ddlRenewNCD.Items.Add(new ListItem("40", "40"));
    //            ddlRenewNCD.Items.Add(new ListItem("50", "50"));
    //            ddlRenewNCD.Text = "50";

    //            divNCDYear.Visible = true;
    //        }
    //        else if (_curNCD == 50)
    //        {
    //            ddlRenewNCD.Items.Add(new ListItem("50", "50"));
    //            ddlRenewNCD.Text = "50";

    //           divNCDYear.Visible = true;
    //        }
    //        divAnyClaim.Visible = false;
    //        txtAnyClaim.Text = "1";
    //        rfvNoOfClaim1.Enabled = false;
    //        rfvNoOfClaim2.Enabled = false;
    //        rfvNoOfClaim3.Enabled = false;

    //        rfvClaimValue1.Enabled = false;
    //        rfvClaimValue2.Enabled = false;
    //        rfvClaimValue3.Enabled = false;

    //        revClaimValue1.Enabled = false;
    //        revClaimValue2.Enabled = false;
    //        revClaimValue3.Enabled = false;
    //    }
    //    else
    //    {
    //        divAnyClaim.Visible = true;
    //        txtAnyClaim.Text = "1";
    //        rfvNoOfClaim1.Enabled = true;
    //        rfvNoOfClaim2.Enabled = true;
    //        rfvNoOfClaim3.Enabled = true;

    //        rfvClaimValue1.Enabled = true;
    //        rfvClaimValue2.Enabled = true;
    //        rfvClaimValue3.Enabled = true;

    //        revClaimValue1.Enabled = true;
    //        revClaimValue2.Enabled = true;
    //        revClaimValue3.Enabled = true;

    //        ddlRenewNCD.Items.Add(new ListItem("0", "0"));
    //        ddlRenewNCD.Items.Add(new ListItem("10", "10"));
    //        ddlRenewNCD.Items.Add(new ListItem("20", "20"));
    //        ddlRenewNCD.Items.Add(new ListItem("30", "30"));
    //        ddlRenewNCD.Items.Add(new ListItem("40", "40"));
    //        ddlRenewNCD.Items.Add(new ListItem("50", "50"));
    //    }
    //}

    //protected void ddlRenewNCD_SelectedIndexChanged(object sender, EventArgs e)
    //{
    //    if (ddlRenewNCD.Text == "50")
    //    {
    //        divNCDYear.Visible = true;
    //    }
    //    else
    //    {
    //        divNCDYear.Visible = false;
    //    }
    //}

    protected void CheckClaim(object sender, EventArgs e)
    {
        ddlRenewNCD.Items.Clear();

        if (ddlNoOfClaim1.Text == "1")
        {
            ddlRenewNCD.Items.Add(new ListItem("0", "0"));
            ddlRenewNCD.Items.Add(new ListItem("10", "10"));
            ddlRenewNCD.Items.Add(new ListItem("20", "20"));
        }
        else if (ddlNoOfClaim1.Text == "-1")
        {
            if (ddlNoOfClaim2.Text == "1")
            {
                ddlRenewNCD.Items.Add(new ListItem("0", "0"));
                ddlRenewNCD.Items.Add(new ListItem("10", "10"));
                ddlRenewNCD.Items.Add(new ListItem("20", "20"));
                ddlRenewNCD.Items.Add(new ListItem("30", "30"));
            }
            else if (ddlNoOfClaim2.Text == "-1")
            {
                if (ddlNoOfClaim3.Text == "1")
                {
                    ddlRenewNCD.Items.Add(new ListItem("0", "0"));
                    ddlRenewNCD.Items.Add(new ListItem("10", "10"));
                    ddlRenewNCD.Items.Add(new ListItem("20", "20"));
                    ddlRenewNCD.Items.Add(new ListItem("30", "30"));
                    ddlRenewNCD.Items.Add(new ListItem("40", "40"));
                }
                else if (ddlNoOfClaim3.Text == "-1")
                {
                    ddlRenewNCD.Items.Add(new ListItem("0", "0"));
                    ddlRenewNCD.Items.Add(new ListItem("10", "10"));
                    ddlRenewNCD.Items.Add(new ListItem("20", "20"));
                    ddlRenewNCD.Items.Add(new ListItem("30", "30"));
                    ddlRenewNCD.Items.Add(new ListItem("40", "40"));
                    ddlRenewNCD.Items.Add(new ListItem("50% (1st year)", "50"));
                    ddlRenewNCD.Items.Add(new ListItem("50% (> one year)", "60"));
                }
                else
                {
                    ddlRenewNCD.Items.Add(new ListItem("0", "0"));
                    ddlRenewNCD.Items.Add(new ListItem("10", "10"));
                    ddlRenewNCD.Items.Add(new ListItem("20", "20"));
                }

            }
            else
            {
                ddlRenewNCD.Items.Add(new ListItem("0", "0"));
                ddlRenewNCD.Items.Add(new ListItem("10", "10"));
            }

        }
        else
        {
            ddlRenewNCD.Items.Add(new ListItem("0", "0"));

        }


    }

    protected void ddlDriverCount_SelectedIndexChanged(object sender, EventArgs e)
    {
        DriverSetting();
    }

    private bool CheckFirstTimeQuote()
    {
        MyDatabase _db = new MyDatabase();
        string _spName = "[sprocAutoEmailFirstQuoteInsertUpdateSingleItem]";

        SortedList _spList = new SortedList();

        string struserid = "0";
        if (Session[General.UserId] != null)
        {
            struserid = Session[General.UserId].ToString();
        }

        _spList.Add("@RefCEUserId", struserid);
        _spList.Add("@EmailType", 100);
        Int64 _retValue = _db.ExecuteSP(_spName, _spList);
        return _retValue == 1;
    }

    private bool SendMailFirstQuoteToUser()
    {
        bool _retVal = false;
        //MyMailManager _mailMgr = new MyMailManager();
        string _emailTo = Session[CE.Global.General.UserEmail].ToString();
        string _customername = Session[CE.Global.General.UserName].ToString();
        string _emailSubject = "First Car Insurance Quote - " + CE.Global.General.GetUTCDateTime().ToString();
        string _mailBody = "";
        string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString();
        string imgLogoUrl = _currentDomainUrl + CE.Configuration.MyConfigurationManager.GetAppSettingValue("LogoPath");
        CompanyInformation _company = new CompanyInformation();
        CompanyInformationDB _companydb = new CompanyInformationDB();
        _company = _companydb.GetCompanyInformation(3);
        string _companyAddress = "";
        string _emailaddress = "";
        string _websiteaddress = "";
        if (_company != null)
        {
            _companyAddress = _company.Address1;
            _emailaddress = _company.EmailAddress;
            _websiteaddress = _company.Website;
        }
        _company = null;
        _companydb = null;

        _mailBody = "Dear " + _customername + ", <br /><br />Thank you for using CompareXpress for the first time.";
        _mailBody += "<br /><br />You are able to view this quote through our Members Area by clicking on the link below. <br /><br /> <a href='http://www.comparexpress.com' target='_blank'>http://www.comparexpress.com</a>.";
        _mailBody += "<br /><br /> Enter your Email and Password to login to the Members Area, located on the top right of the page.";
        _mailBody += "<br /><br />If you have any questions, comments, or feedback, please do not hesitate to contact us at <a href='mailto:support@comparexpress.com'>support@comparexpress.com</a>.";
        _mailBody += "<br /><br />Best Regards,<br /><br />Your CompareXpress Team<br/>Customer Support - SG/International";
        _mailBody += "<br /><img src='" + imgLogoUrl + "' />";
        _mailBody += "<br /><hr />";
        _mailBody += _companyAddress;
        _mailBody += "<br /><a href='" + _websiteaddress + "' target='_blank'>" + _websiteaddress + "</a> :: <a href='mailto:" + _emailaddress + "' target='_blank'>" + _emailaddress + "</a><br /><hr />";
        _mailBody += "<br /><i>This is a computer-generated email. Please do not reply to this email.</i>";
        if (MyMailManager.SendCRMMessage(_emailTo, _emailSubject, _mailBody))
        {
            _retVal = true;
        }
        else
        {
            _retVal = false;
        }

        return _retVal;
    }

    protected void ddlCarMake_SelectedIndexChanged(object sender, EventArgs e)
    {
        //System.Threading.Thread.Sleep(5000);
        GenerateCarModel(Convert.ToInt32(ddlCarMake.Text), ddlCarMake.SelectedItem.Text);
    }

    private void CheckCustomCarMakeModel(bool OnOff)
    {
        divCarMakeModel.Visible = OnOff;
        rfvCustomCarMakeModel.Enabled = OnOff;

        ddlCarModel.Enabled = !OnOff;
        ddlCarMake.Enabled = !OnOff;

        rfvCarMake.Enabled = !OnOff;
        rfvCarModel.Enabled = !OnOff;
    }

    protected void chkCannotfind_CheckedChanged(object sender, EventArgs e)
    {
        CheckCustomCarMakeModel(chkCannotfind.Checked);
    }
}
